๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

BE/Spring

[Spring] ๋ฉ”์ด๋ธ(Maven)๊ณผ pom.xml

๐Ÿ“Œpom.xml ์ •์˜

pom.xml์€ ๋ฉ”์ด๋ธ(Maven)์˜ ๋นŒ๋“œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ํŒŒ์ผ์ด๋‹ค.

๐Ÿ“Œ์—ฌ๊ธฐ์„œ ๋ฉ”์ด๋ธ(Maven)์ด๋ž€?

์ž๋ฐ” ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌ ํˆด์œผ๋กœ, ๋ฏธ๋ฆฌ ์ž‘์„ฑ๋œ xml ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ฑฐ๋‚˜, ์ƒ์„ฑ, ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ ํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์„ ์ž๋™ํ™”ํ•œ๋‹ค. ๋ฉ”์ด๋ธ์˜ ๊ธฐ๋Šฅ์—๋Š” ๋Œ€๋žต 1) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ด€๋ฆฌ  2) ๋นŒ๋“œ ๊ธฐ๋Šฅ์ด ์žˆ๋‹ค.๋˜ํ•œ, pom.xml์€ ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์— ๋ณต์‚ฌ/๋ถ™์—ฌ๋„ฃ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ”์šฉ์„ฑ์ด ์ข‹๋‹ค. STS(Spring Tools Suite)๋Š” ์ด๋Ÿฌํ•œ ๋ฉ”์ด๋ธ์„ ๋‚ด์žฅํ•˜๊ณ  ์žˆ๋‹ค. ๋ฉ”์ด๋ธ์€ ์ด pom.xml์— ์“ฐ์—ฌ์ง„ ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ๋‚ด์žฅํ•ด์„œ ํ”„๋กœ๊ทธ๋žจ์„ ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•œ๋‹ค. ๋ฉ”์ด๋ธ์„ ์‚ฌ์šฉํ•œ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” pom.xml์„ ์–ผ๋งˆ๋‚˜ ์ œ๋Œ€๋กœ ์„ค์ •ํ•˜๋Š๋ƒ๊ฐ€ ์ค‘์š”ํ•˜๋‹ค.

 

๐Ÿ“Œpom.xml์˜ ๊ธฐ๋ณธ ํ˜•ํƒœ 

pom.xml์€ ํŒŒ์ผ ํ˜•์‹์ด XML์ด๋ฏ€๋กœ ํƒœ๊ทธ ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. 

<project> ํƒœ๊ทธ : ๋ฃจํŠธ ํƒœ๊ทธ์ด๋ฉฐ ๋ฉ”์ด๋ธ์˜ XML ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

<modelVersion> : ๋ฉ”์ด๋ธ์˜ ๋ชจ๋ธ ๋ฒ„์ „

<groupID> : ๊ทธ๋ฃน ID์˜ ํƒœ๊ทธ 

<artifactID> : ์•„ํ‹ฐํŒฉํŠธID์˜ ํƒœ๊ทธ 

<version> : ๋ฒ„์ „๋ช… ํƒœ๊ทธ

<packaging> : ํŒจํ‚ค์ง• ํ˜•์‹์„ ์ง€์ •ํ•˜๋Š” ํƒœ๊ทธ ex) war

<name> : ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ 

<url> : ๋ฉ”์ด๋ธ์˜ url 

<properties> : ํ”„๋กœ์ ํŠธ ๊ด€๋ จ ์†์„ฑ

<parent> : pom.xml์˜ ์ƒ์†์— ๊ด€๋ จ๋œ ํƒœ๊ทธ 

<dependencies> : ํ”„๋กœ์ ํŠธ๊ฐ€ ์˜์กดํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์˜ ์ •๋ณด 

 

<dependency> ์— ๊ด€ํ•˜์—ฌ

<dependency>๋Š” ํ”„๋กœ์ ํŠธ์— ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ  ์ •์˜ํ•˜๋Š” ํƒœ๊ทธ์ด๋‹ค.

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” groupId์™€ artifactId๋กœ ๊ตฌ๋ณ„๋˜๋ฏ€๋กœ, ์ด ๋‘ ๊ฐ€์ง€ ํƒœ๊ทธ๋Š” <dependency>์— ๊ผญ ์ž…๋ ฅํ•ด์ฃผ์–ด์•ผํ•œ๋‹ค.

  • <groupId> : ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๊ทธ๋ฃน ID
  • <artifactId> : ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์•„ํ‹ฐํŒฉํŠธ ID 
  • <version> : ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๋ฒ„์ „
  • <scope> : ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฒ”์œ„

 

๐Ÿ“Œpom.xml ์˜ˆ์‹œ 

spring MVC Project์— jdbc, spring-test, mybatis ๋“ฑ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค. 

<?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.example</groupId>
	<artifactId>project</artifactId>
	<name>project</name>
	<packaging>war</packaging>
	<version>1.0.0-BUILD-SNAPSHOT</version>
	<properties>
		<java-version>1.8</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>
	<!-- ์˜ค๋ผํด -->
	<repositories>
		<repository>
			<id>oracle</id>
			<url>http://maven.jahia.org/maven2</url>
		</repository>
	</repositories>
	<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>    
     	
     	<!-- spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        
        <!-- spring-test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework-version}</version>
            <scope>test</scope>
        </dependency>
     
        <!-- log4jdbc-log4j2-jdbc4 -->
        <dependency>
            <groupId>org.bgee.log4jdbc-log4j2</groupId>
            <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
            <version>1.16</version>
        </dependency>
  
  		<!-- org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
      
        <!-- mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>    
        
        <dependency>
			 <groupId>org.json</groupId>
			 <artifactId>json</artifactId>
			 <version>20090211</version>
		</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>