注:本人是使用tomcat7应用服务器演示,tomcat版本与插件需要保持一致性(插件版本<version>2.0</version>),否则会出现错误。
1、在pom.xml文件的build增加下面的代码,相应的地方修改账号和密码(与tomcat账号密码保持一致):
... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-plugin.version}</version> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.0</version> <configuration> <url>http://123.56.94.59:9090/manager/text</url> <server>tomcat</server> <username>admin</username> <password>admin</password> <path>/o2test</path> <update>true</update> </configuration> </plugin> ...
2、修改apache-tomcat-7.0.47\conf\tomcat-users.xml文件,增加如下代码:
<role rolename="admin-gui"/> <role rolename="admin-script"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
3、运行tomcat7:deploy命令,例如:
Tomcat 7 Deploy URL = http://localhost:8080/manager/text Command = mvn tomcat7:deploy Tomcat 6 Deploy URL = http://localhost:8080/manager/ Command = mvn tomcat6:deploy
类似如下日志,运行成功:
29572/29586 KB 29574/29586 KB 29576/29586 KB 29578/29586 KB 29580/29586 KB 29582/29586 KB 29584/29586 KB 29586/29586 KB Uploaded: http://123.56.94.59:9090/manager/text/deploy?path=%2Fyoodb&update=true (29586 KB at 57.7 KB/sec) [INFO] tomcatManager status code:200, ReasonPhrase:OK [INFO] OK - Deployed application at context path /yoodb [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] yoodb ............................................. SUCCESS [ 3.704 s] [INFO] service ........................................... SUCCESS [ 1.850 s] [INFO] web ............................................... SUCCESS [08:41 min] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 08:46 min [INFO] Finished at: 2015-03-17T14:26:19+08:00 [INFO] Final Memory: 30M/178M [INFO] ------------------------------------------------------------------------
4、tomcat热部署,在配置文件增加如下代码:
<Context path="/test" docBase="D:/workspace/test/webapp" debug="0" reloadable="false"> reloadable="false"此参数默认false,要么不写,要写设置为false,即热部署