Tool - [maven] Spring+Maven 원격 Tomcat 서버에 배포하기
목록 추천  
추천수:
제 목 [maven] Spring+Maven 원격 Tomcat 서버에 배포하기
작성자 박세청 작성일 2014/01/01 23:01


Spring+Maven 원격 Tomcat 서버에 배포하기

 

이번 포스트는 로컬개발환경에서 운영서버로 웹어플리케이션을 배포하는 것이다.

그간 Maven을 사용하지 않아서 운영서버 Tomcat 관리페이지로 가서 .war 파일을 직접 Deploy 해주었었다.

여간 귀찮은게 아님 ㅋㅋㅋ

그래서 Maven을 사용해서 내 로컬PC에서 서버로 배포하기로 함.

먼저 운영서버의 톰캣 유저 권한을 수정좀 해주셔야 합니다.

운영서버 Tomcat 설치에 가셔서 conf\tomcat-user.xml 파일을 건드려줍시다.

<!-- tomcat-user.xml -->

  1. <tomcat-users>
  2. <user name="name" password="password" roles="admin-gui,manager-gui,manager-script" />
  3. </tomcat-users>

위와 같이 manager-script 라는 권한을 부여해줍시다.

설정적용을 위해 운영톰캣서버를 한번 재가동!

자이제 다시 개발환경으로 넘어옵니다.

개발환경의 pom.xml 파일에 플러그인을 설치해줍니다.

<!-- pom.xml -->

  1. <plugins>
  2. <plugin>
  3. <artifactId>maven-eclipse-plugin</artifactId>
  4. <version>2.9</version>
  5. <configuration>
  6. <additionalProjectnatures>
  7. <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
  8. </additionalProjectnatures>
  9. <additionalBuildcommands>
  10. <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
  11. </additionalBuildcommands>
  12. <downloadSources>true</downloadSources>
  13. <downloadJavadocs>true</downloadJavadocs>
  14. </configuration>
  15. </plugin>
  16. <plugin>
  17. <groupId>org.apache.maven.plugins</groupId>
  18. <artifactId>maven-compiler-plugin</artifactId>
  19. <version>2.5.1</version>
  20. <configuration>
  21. <source>1.6</source>
  22. <target>1.6</target>
  23. <compilerArgument>-Xlint:all</compilerArgument>
  24. <showWarnings>true</showWarnings>
  25. <showDeprecation>true</showDeprecation>
  26. </configuration>
  27. </plugin>
  28. <plugin>
  29. <groupId>org.codehaus.mojo</groupId>
  30. <artifactId>exec-maven-plugin</artifactId>
  31. <version>1.2.1</version>
  32. <configuration>
  33. <mainClass>org.test.int1.Main</mainClass>
  34. </configuration>
  35. </plugin>
  36. <plugin>
  37. <groupId>org.apache.maven.plugins</groupId>
  38. <artifactId>maven-war-plugin</artifactId>
  39. <version>2.4</version>
  40. <configuration>
  41. <warsourcedirectory>src/main/webapp</warsourcedirectory>
  42. <webxml>src/main/webapp/WEB-INF/web.xml</webxml>
  43. </configuration>
  44. </plugin>
  45. <plugin>
  46. <groupId>org.codehaus.mojo</groupId>
  47. <artifactId>tomcat-maven-plugin</artifactId>
  48. <version>1.1</version>
  49. <configuration>
  50. <url>http://localhost:8000/manager/text</url>
  51. <path>/wia</path>
  52. <username>name</username>
  53. <password>password</password>
  54. </configuration>
  55. </plugin>
  56. </plugins>

아마 빨간글씨 플러그인 빼고는 자동적으로 설정되어 있으실꺼에요.

저 빨간글씨 부분 추가해줍니다.

플러그인이 tomcat7-maven-plugin 도 있더라구요.

톰캣7 버전에 최적화 되어있고 그에따라 기능도 제가 사용한 플러그인보다 더 많은 것 같습니다.

url 에 배포할 원격지 서버 주소를 적어주시면 되고요. 보안상 블로그에는 localhost라고 명시하겠습니다;;

톰캣7 부터는 .../text 라고 해주어야 한다는 군요... 경로가 바뀐듯...

path는 / 로 해주시던지 자신이 원하는 path 적어주시면되고요

나머지 username과 password 는 원격지 톰캣서버의 계정대로 써주시면 됩니다.

다됐습니다. 이제 maven을 실행시켜서 배포합시다!

프로젝트 - 마우스 우클릭 - Run As - Run Configurations...

( 설정 후에는 Maven build 만 선택하셔도 됩니다. )



Maven Build 더블클릭하시면 위 그림과 같이 생길꺼구요.

Name은 Build 명이되겠구요.

Base directory 는 자동으로 잡혀 있을텐데 안잡혀 있다면 Browse Workspace 누르셔서 해당 프로젝트 선택해주시면 됩니다.

Goals 에 입력을 해주시면 되는데

처음 하실때는 tomcat:deploy 만 해주시면 되고요.

다시 수정, 재배포 하실때에는 tomcat:undeploy tomcat:deploy 해주시면 이전에 배포된것을 지우고 재배포합니다.

그래서 그 해당 서버에 첨부파일들이 삭제될 수있으니... 알아서 ....

Apply 후 Run 클릭하시면 배포 테스트 후 배포 시킵니다.

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Springsetting 1.1.2-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:undeploy (default-cli) @ wia ---
[INFO] Undeploying application at http://localhost:8000/wia
[INFO] OK - Undeployed application at context path /wia
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:deploy (default-cli) @ wia >>>
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ wia ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ wia ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ wia ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ wia ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ wia ---
[INFO] Surefire report directory: C:UsersDELLDocuments백업HDwia argetsurefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-war-plugin:2.4:war (default-war) @ wia ---
[INFO] Packaging webapp
[INFO] Assembling webapp [wia] in [C:UsersDELLDocuments백업HDwia argetwia-1.1.2-BUILD-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:UsersDELLDocuments백업HDwiasrcmainwebapp]
[INFO] Webapp assembled in [369 msecs]
[INFO] Building war: C:UsersDELLDocuments백업HDwia argetwia-1.1.2-BUILD-SNAPSHOT.war
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:deploy (default-cli) @ wia <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:deploy (default-cli) @ wia ---
[INFO] Deploying war to http://localhost:8000/wia
[INFO] OK - Deployed application at context path /wia
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.172s
[INFO] Finished at: Thu Dec 05 14:28:51 KST 2013
[INFO] Final Memory: 9M/151M
[INFO] ------------------------------------------------------------------------

자그럼 이제 원격서버에서 실행시켜보시면 개발환경과 똑같이 배포된 것을 확인하실 수 있으실 겁니다.

이상입니다.

P.s) 위 글에는 localhost로 로컬에서 작업한거 같이 되어있는데 서버에 배포후 보안상 포스트에만 localhost로 수정해준것입니다.





이전글 [eclipse] Eclipse Juno에 Spring + Maven 환경설정 및 테스트
다음글 [eclipse] eclipse 에서 STS 를 사용한 Spring web 프로젝트 생성

목록 추천