maven-deploy-plugin ์‚ฌ์šฉ

๋˜ ๋‹ค๋ฅธ ๋งค์šฐ ํฅ๋ฏธ๋กœ์šด ์ฃผ์ œ๋Š” ์กฐ๋ฆฝ๋œ ํŒจํ‚ค์ง€์˜ ์ž๋™ ๋ฐฐํฌ์ž…๋‹ˆ๋‹ค. Maven์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž์ฒด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ตฌ์ถ•ํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋กœ์ปฌ, ํšŒ์‚ฌ ๋˜๋Š” ์ค‘์•™ Maven ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์–ด๋–ป๊ฒŒ ์ž๋™์œผ๋กœ ํ‘ธ์‹œํ•ฉ๋‹ˆ๊นŒ?

Maven์—๋Š” ์ด๋ฅผ ์œ„ํ•œ ํŠน๋ณ„ํ•œ maven-deploy-plugin ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์žˆ์Šต๋‹ˆ๋‹ค . ์˜ˆ:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
    	<version>2.5</version>
    	<configuration>
          <file>${project.build.directory}\${project.artifactId}-src.zip</file>
          <url>${project.distributionManagement.repository.url}</url>
          <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
          <groupId>${project.groupId}</groupId>
          <artifactId>${project.artifactId}</artifactId>
          <version>${project.version}</version>
      	  <packaging>zip</packaging>
          <pomFile>pom.xml</pomFile>
    	</configuration>
  	</plugin>

์ด๋Ÿฌํ•œ ์„ค์ •์„ ์‚ฌ์šฉํ•˜๋ฉด ๋นŒ๋“œ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์œ ํšจํ•œ ํŒจํ‚ค์ง€๋กœ Maven ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ํ‘ธ์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ”„๋กœ์„ธ์Šค๋ฅผ ์ž์„ธํžˆ ๋ถ„์„ํ•˜์ง€๋Š” ์•Š์ง€๋งŒ ์—ฌ๊ธฐ์—์„œ ๋ฌด์Šจ ์ผ์ด ์ผ์–ด๋‚˜๊ณ  ์žˆ๋Š”์ง€ ๊ฐ„๋‹จํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

ํŒŒ์ผ ํƒœ๊ทธ๋Š” Maven ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์ƒˆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ํ‘ธ์‹œ๋  ํŒŒ์ผ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

url ํƒœ๊ทธ๋Š” Maven ์ €์žฅ์†Œ(local/corporate/โ€ฆ)์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

repositoryId ํƒœ๊ทธ๋Š” ๋ฐฐํฌ๊ฐ€ ์ด๋ฃจ์–ด์งˆ ์ €์žฅ์†Œ์˜ ์‹๋ณ„์ž๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

groupId , artifactId , version ํƒœ๊ทธ๋Š” Maven ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ํ‘œ์ค€ ํŒจํ‚ค์ง€ ์‹๋ณ„์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์ด ์„ธ ๊ฐ€์ง€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒจํ‚ค์ง• ํƒœ๊ทธ๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋‹จ์ผ zip ํŒŒ์ผ๋กœ ์ „์†ก๋˜๋„๋ก ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์—ฌ๋Ÿฌ ๊ฐœ์˜ jar ํŒŒ์ผ์ด ์žˆ๋”๋ผ๋„ ํ•˜๋‚˜์˜ jar ํŒŒ์ผ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

pomFile ํƒœ๊ทธ๋Š” ์„ ํƒ ์‚ฌํ•ญ์ด๋ฉฐ ์ˆจ๊ฒจ์ง„ ๋ฐ์ดํ„ฐ๋‚˜ ์˜ค๋ฒ„ํ—ค๋“œ ๋ฐ์ดํ„ฐ๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š” ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ๋‹ค๋ฅธ pom.xml์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Maven์„ ์‚ฌ์šฉํ•˜์—ฌ Tomcat์— ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ

Java ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ์›น ์„œ๋ฒ„๋Š” Apache Tomcat ์ž…๋‹ˆ๋‹ค . ๋ฌผ๋ก  Maven์˜ ๋„์›€์œผ๋กœ war ํŒŒ์ผ์„ ๋กœ์ปฌ ๋˜๋Š” ์›๊ฒฉ Tomcat ์„œ๋ฒ„์— ์ง์ ‘ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‚˜์ค‘์— Tomcat์„ ์„ค์น˜ํ•˜๊ณ  ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šฐ๊ฒŒ ๋˜์ง€๋งŒ ์ง€๊ธˆ์€ ์›น ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ ์ž๋™ ๋ฐฐํฌ์— ๋Œ€ํ•œ ์ฃผ์ œ๋งŒ ๋‹ค๋ฃฐ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

1๋‹จ๊ณ„. Tomcat ์„œ๋ฒ„์— Maven ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด Apache Tomcat์ด ์••์ถ• ํ•ด์ œ๋œ ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ conf/tomcat-users.xml ํŒŒ์ผ์„ ์—ด๊ณ  manager-gui ๋ฐ manager-script ์—ญํ• ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค .

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="admin" roles="manager-gui,manager-script" />
</tomcat-users>

2๋‹จ๊ณ„. Maven์ด Tomcat์— ์•ก์„ธ์Šคํ•˜๋„๋ก ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด $MAVEN_HOME/conf/settings.xml ํŒŒ์ผ์„ ์—ด๊ณ  ์„œ๋ฒ„๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>
<settings ...>
  <servers>
	<server>
  	<id>TomcatServer</id>
  	<username>admin</username>
  	<password>admin</password>
	</server>
  </servers>
</settings>

3๋‹จ๊ณ„. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ Apache Tomcat์— ์ž๋™์œผ๋กœ ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•œ ํŠน์ˆ˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋Ÿฌ๊ทธ์ธ ์ด๋ฆ„์€ tomcat7-maven-plugin ์ž…๋‹ˆ๋‹ค . ๊ทธ๋Ÿฐ๋ฐ ์ด๋ฆ„์—์„œ ์ง์ž‘ํ•  ์ˆ˜ ์žˆ๋“ฏ์ด Maven ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“  ๊ฒƒ์ด ์•„๋‹ˆ๋ผ Tomcat ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

	<build>
    	<plugins>
        	<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
            	<configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <server>TomcatServer</server>
                	<path>/simpleProject</path>
            	</configuration>
        	</plugin>
    	</plugins>
	</build>

๊ตฌ์„ฑ ์„น์…˜์—์„œ ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

  • url ์€ Tomcat์ด ์‹คํ–‰ ์ค‘์ธ ์ฃผ์†Œ์™€ manager/text ์˜ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
  • ์„œ๋ฒ„ - settings.xml ํŒŒ์ผ ์˜ ์„œ๋ฒ„ ID
  • ๊ฒฝ๋กœ - ๋ฐฐํฌ๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ฃผ์†Œ

๋ฐฐํฌ ๊ด€๋ฆฌ ๋ช…๋ น:

mvn tomcat7:๋ฐฐํฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ Tomcat์— ๋ฐฐํฌ
mvn tomcat7:๋ฐฐํฌ ํ•ด์ œ Tomcat์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ œ๊ฑฐ
mvn tomcat7:์žฌ๋ฐฐํฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์žฌ๋ฐฐํฌ

Cargo ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ ๋ฐฐํฌ

์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ ๋˜ ๋‹ค๋ฅธ ์œ ์šฉํ•˜๊ณ  ๋‹ค์žฌ๋‹ค๋Šฅํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ Cargo Plugin ์ž…๋‹ˆ๋‹ค . ๊ทธ๋Š” ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ์›น ์„œ๋ฒ„๋กœ ์ž‘์—…ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Apache Tomcat์—์„œ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<build>
    <plugins>
    	<plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
        	<version>1.9.10</version>
        	<configuration>
            	<container>
                	<containerId>tomcat8x</containerId>
                    <type>installed</type>
                	<home>Insert absolute path to tomcat 7 installation</home>
            	</container>
            	<configuration>
                    <type>existing</type>
                    <home>Insert absolute path to tomcat 7 installation</home>
            	</configuration>
        	</configuration>
   	    </plugin>
    </plugins>
</build>

๋กœ์ปฌ Tomcat์— ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„ค์น˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

mvn install
mvn cargo:deploy

์›๊ฒฉ ์›น ์„œ๋ฒ„์— ๋ฐฐํฌํ•˜๋ ค๋ฉด ์ด ์„œ๋ฒ„์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ๊ถŒํ•œ์„ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด pom.xml ์— ๋“ฑ๋กํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค .

<configuration>
	<container>
        <containerId>tomcat8x</containerId>
    	<type>remote</type>
	</container>
	<configuration>
    	<type>runtime</type>
    	<properties>
            <cargo.remote.username>admin</cargo.remote.username>
            <cargo.remote.password>admin</cargo.remote.password>
        	<cargo.tomcat.manager.url>http://localhost:8080/manager/text</cargo.tomcat.manager.url>
    	</properties>
	</configuration>
</configuration>

IntelliJ IDEA๋กœ ๋ฐฐํฌ

Intellij IDEA๊ฐ€ ๋ชจ๋“  ์ž‘์—…์„ ์ž์ฒด์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ ์„ค์น˜๋œ Tomcat ๋งŒ ์žˆ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค .

1๋‹จ๊ณ„. ๋กœ์ปฌ Tomcat ๊ตฌ์„ฑ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

2๋‹จ๊ณ„. ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋กœ์ปฌ Tomcat์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

3๋‹จ๊ณ„. ํ†ฐ์บฃ ๊ตฌ์„ฑ:

4๋‹จ๊ณ„. Tomcat ํด๋”์— ๊ฒฝ๋กœ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

5๋‹จ๊ณ„. ํ”„๋กœ์ ํŠธ๋ฅผ Tomcat์— ์•„ํ‹ฐํŒฉํŠธ๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด ๋ฐฐํฌ ํƒญ์œผ๋กœ ์ด๋™ํ•˜์—ฌ ์˜ค๋ฅธ์ชฝ์˜ + ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค .

๊ทธ๊ฒŒ ๋‹ค์•ผ.

๊ทธ๋Ÿฐ๋ฐ ์›๊ฒฉ ์„œ๋ฒ„์— ๋ฐฐํฌํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๋‘ ๋ฒˆ์งธ ๋‹จ๊ณ„์—์„œ Remote Tomcat์„ ์„ ํƒํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.