본문 바로가기
IT 개발/SPRING

SPRING 구성 도구 설치

by Love of fate 2021. 3. 14.
728x90
반응형

[프로젝트 구성 도구 설치]

스프링 프레임워크에는 다양한 모듈이 존재한다. 핵심 모듈인 spring-core, spring-beans, spring-context, spring-aop를 비롯한 spring-webmvc, spring-jdbc, spring-tx 등 다양한 모듈이 존재한다. 

각 모듈은 스프링 프레임워크에 포함되어 있지 않은 다른 모듈을 필요로 한다. 

예를들어 spring-aop 모듈은 aopalliance 모듈을 필요로 하고, spring-orm 모듈은 JPA나 하이버네이트 모듈을 필요로 한다. 

 

각 모듈은 모두 메이븐 중앙 리포지토리를 통해서 배퐂되고 있다. 자바 프로젝트를 구성할 때 주로 사용하는 빌드 도구인 메이븐과 그레이들 둘 다 메입느 리포지토리를 지원한다. 

 

-- 프로젝트 폴더 생성

메이븐과 그레이들 모두 동일한 폴더 구조를 사용한다. 프로젝트를 생성할 기준 폴더를 C:spring5fs 폴더가 없다면 일단 이 폴더부터 만든다. spring5fs 폴더를 생성한 다음 sp5-chap02 폴더를 생성한다.

그리고 비슷한 방식으로 src, main, java 폴더를 차례대로 생성한다.

* 여기서 주의할 점은 java 폴더는 main 폴더의 하위폴더라는 점이다.

  -  C:\spring5fs\sp5-chap02\ :  프로젝트 폴더

  -  C:\spring5fs\sp5-chap02\src\main\java : 자바 소스 폴더

 

[메이븐 프로젝트 생성]

메이븐 프로젝트 설정 파일 작성

C:\spring5fs\sp5-chap02 폴더에 pom.xml 파일을 XML 파일로 작성한다. 윈도우즈에서 기본으로 제공하는 메모장보다는 다양한 편집기능을 제공하는 텍스트 편집기 (sublink, notepad++ 등)을 사용해서 작성하면 편리하다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.nam</groupId>
    <artifactId>project</artifactId>
    <name>namProject</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
                
        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>    
        
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
 
        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
                
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>        
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
XML 소스가 다소 길다. 처음 pom.xml을 작성할 때 많이 하는 실수가 오타를 입력하는 것이다. 
오타를 입력하면 메이븐 프로젝트를 이클립스에서 임포트할 수 없으므로 지붖ㅇ해서 입력할 것!

6행 : 프로젝트의 식별자를 지정한다. 여기서는 프로젝트 폴더와 동일한 이름인  sp5-chap02를 사용한다. 

18행 ~ 29행 : 프로젝트에서 5.0.2.RELEASE 버전의 spring-context 모듈을 사용한다고 설정한다. 

136행 ~ 147행 : 1.6 버전을 기준으로 자바 소스를 컴파일하고 결과 클래스를 생성한다. 자바 컴파일러가 소스코드를 읽을 때 사용할 인코딩은 UTF-8로 설정 할 수 있다. 

 

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>utf-8<encoding>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>

 

728x90
반응형