采用maven 对tomcat 进行自动部署
在工作过程中经常会遇到项目频繁发不到额过程,而且在这个过程中会一直进行一些简单但是繁琐的重复性工程 1、打war 包 2、停掉tomcat 3、copy war 包 4、启动tomcat 听说maven 可以替代这行操作,所以放手一试
还是一如既往的废话不多说,直接开门见山
步骤如下:
1、下载一个绿色版完整的tomcat 包
2、进入tomcat/conf 文件下修改文件 tomcat-users.xml文件
1
2
3
4
5
6
7
|
<tomcat- users > <role rolename= "admin" /> <role rolename= "manager" /> <role rolename= "manager-gui" /> <role rolename= "manager-script" /> <user username= "admin" password= "admin" roles= "admin,manager,manager-gui,manager-script" /> <tomcat- users /> |
修改完成之后,重启tomcat 访问http://192.168.3.141:8050/manager/html 此处是本人自己私服的 IP:PROT
页面如下
3、配置项目pom.xml 文件
1
2
3
4
5
6
7
8
9
10
|
<plugin> <groupId>org.codehaus.mojo< /groupId > <artifactId>tomcat-maven-plugin< /artifactId > <version>1.1-SNAPSHOT< /version > <configuration> <url>http: //192 .168.3.141:8050 /manager/text < /url > <server>tomcat< /server > <path>/< /path > < /configuration > < /plugin > |
注:此处的url 注意是xxx/manager/text 并非是 xxx/manager/html 原因是我用的tomcat 是tomcat7 的版本
4、配置maven 的setting.xml 文件
1
2
3
4
5
|
<server> < id >tomcat< /id > <username>admin< /username > <password>admin< /password > < /server > |
5、ok 到此一切配置工作配置完毕
开始运行 mvn tomcat:redeploy
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
|
Jerry:prjGuSi Jerry$ mvn tomcat:redeploy [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building prjGuSi Maven Webapp 5.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> tomcat-maven-plugin:1.1-SNAPSHOT:redeploy (default-cli) @ prjGuSi >>> [WARNING] The artifact freemarker:freemarker:jar:2.3.9 has been relocated to org.freemarker:freemarker:jar:2.3.9 [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ prjGuSi --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 15 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ prjGuSi --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 64 source files to /Users/Jerry/work/IdeaProjects/branch/prjGuSi/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ prjGuSi --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /Users/Jerry/work/IdeaProjects/branch/prjGuSi/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ prjGuSi --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.6: test (default- test ) @ prjGuSi --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ prjGuSi --- [INFO] Packaging webapp [INFO] Assembling webapp [prjGuSi] in [ /Users/Jerry/work/IdeaProjects/branch/prjGuSi/target/ROOT ] [INFO] Processing war project [INFO] Copying webapp resources [ /Users/Jerry/work/IdeaProjects/branch/prjGuSi/src/main/webapp ] [INFO] Webapp assembled in [350 msecs] [INFO] Building war: /Users/Jerry/work/IdeaProjects/branch/prjGuSi/target/ROOT .war [INFO] WEB-INF /web .xml already added, skipping [INFO] [INFO] <<< tomcat-maven-plugin:1.1-SNAPSHOT:redeploy (default-cli) @ prjGuSi <<< [INFO] [INFO] --- tomcat-maven-plugin:1.1-SNAPSHOT:redeploy (default-cli) @ prjGuSi --- [INFO] Deploying war to http: //192 .168.3.141:8050/ [INFO] OK - Deployed application at context path / [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time : 21.527s [INFO] Finished at: Sun Jul 27 16:32:52 CST 2014 [INFO] Final Memory: 22M /439M [INFO] ------------------------------------------------------------------------ |
ok,可以看出部署成功…… 针对此次试水,遇到的问题分析请移步 -》》》》http://my.oschina.net/jerryhu/blog/295279