之前一直是手动把打好的包上传到服务器,然后手动启动tomcat,或者使用Jenkins,前面这两种方式感觉都不太好,后来发现maven有个tomcat7-maven-plugin插件,配置好之后,在idea里面执行一下命令,就自动发布到远程tomcat,自动启动tomcat,多好的东西,为啥现在才发现呢![大哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
![大哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
,我用的是tomcat8,这个插件看名字应该是用来发布到tomcat7的,不过也可以发布到tomcat8,mvnrepository.com里面也可以搜到tomcat8-maven-plugin,我没有试,有兴趣的可以试试,说了这么多废话,下面说一下具体步骤
![大哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
![大哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
![大哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
1、准备好tomcat8、maven3,编辑器我用的idea15,tomcat8 webapps下面本身的manager不能删了,删了就不行了,这个很重要
2、修改tomcat-users.xml,加上用户名密码权限
<role rolename="tomcat"/> <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="manager-script" /> <role rolename="manager-jmx" /> <role rolename="manager-status" /> <role rolename="admin-gui"/> <user username="admin" password="admin" roles="tomcat,manager,manager-script,admin-gui,manager-jmx,manager-status" />
3、打开tomcat/webapps/manager/META-INF/context.xml注释掉下面的代码,这个是限制ip访问的,否则会报403
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
4、打开项目的pom.xml文件,在build/plugins里面加上
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://ip:port/manager/text</url> <server>tomcat8</server> <path>/ROOT</path> <charset>utf8</charset> <update>true</update> </configuration> </plugin>5、打开本地maven的settings.xml文件,在servers里面加上
<server>
<id>tomcat8</id>
<username>admin</username>
<password>admin</password>
</server>
6、执行maven命令mvn clean package -Dmaven.test.skip=true -Ptest tomcat7:deploy第一次部署执行这个命令,前提是tomcat必须是已经启动了,后面再部署执行下面的redeploy命令mvn clean package -Dmaven.test.skip=true -Ptest tomcat7:redeploy7、至此就完事了,就可以愉快的看到命令输出的日志了[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ rrs-core --- [INFO] Deploying war to http://2.2.2.2:18881/ROOT Uploading: http://2.2.2.2:18881/manager/text/deploy?path=%2FROOT&update=true Uploaded: http://2.2.2.2:18881/manager/text/deploy?path=%2FROOT&update=true (22173 KB at 2486.2 KB/sec) [INFO] tomcatManager status code:200, ReasonPhrase: [INFO] OK - Deployed application at context path [/] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.598 s [INFO] Finished at: 2017-06-09T15:39:55+08:00 [INFO] Final Memory: 29M/354M [INFO] ------------------------------------------------------------------------