maven3.5+tomcat8.5 实现自动部署测试
第一步,开启tomcat远程部署
(一)
在tomcat的conf下的tomcat-users.xml。在server字段添加。
<role rolename="manager"/>
<role rolename="admin"/>
<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="xiaoyu" password="xiaoyu" roles="manager,admin,manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
username为登录tomcat远程部署的用户名, password为登录的密码,根据自己的喜好设置。
(二)修改webapps/manager/META-INF/context.xml
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
此设置只允许本机部署,不允许远程登录,改为
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
(三)假如war包过大,会造成无法上传的的现象,需要做一下修改配置。
修改${tomcat_root}/webapps/manager/WEB-INF/web.xml中的
<multipart-config>
<!-- 50MB max -->
<!--<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>-->
<!-- 100MB max-->
<max-file-size>104758600</max-file-size>
<max-request-size>104758600</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
二,在maven项目下的pom.xml修改增加,
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1756463</version>
<configuration>
<url>http://192.168.0.7:8850/manager/text</url>
<server>tomcat8</server>
<path>/BMS</path> /BMS为项目的名称,打包为BMS.war
<charset>utf8</charset>
<update>true</update>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
三,修改maven下的settings.xml
增加,如下字段,
<server>
<id>tomcat8</id>
<username>xiaoyu</username>
<password>xiaoyu</password>
</server>
首次使用,mvn tomcat8:deploy,第一次maven下载较多的文件,较慢,以后使用mvn tomcat8:redeploy