项目环境
tomcat7 和maven3.3.9
正确部署过程
步骤一:修改修改tomcat的conf目录下tomcat-users.xml文件,在<tomcat-users>项中添加
<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="12345" roles="manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
步骤二:修改maven的conf目录下settings.xml文件
1.在<servers>中增加
<server>
<id>tomcat</id>
<username>admin</username>
<password>12345</password>
</server>
这三个字段的值是自己定的
2.在<pluginGroups>字段中添加
<pluginGroup>org.codehaus.modello</pluginGroup>
步骤三:配置项目的pom.xml文件,向其中增加如下字段
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat</server>
<username>admin</username>
<password>12345</password>
<path>/enjoyread</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
其中的字段<server>tomcat</server>,<username>admin</username>,<password>12345</password>的值和maven的conf目录下settings.xml配置的<id>tomcat</id>,<username>admin</username>,<password>12345</password>值对应
步骤四:发布
使用 mvn tomcat7:deploy 命令发布
配置成功结果
[INFO] Including org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing D:\WorkSpace\enjoyread\target\enjoyread.war with D:\WorkSpace\enjoyread\target\enjoyread-1-shaded.war
[INFO] Dependency-reduced POM written at: D:\WorkSpace\enjoyread\dependency-reduced-pom.xml
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.2:redeploy (default-cli) < package @ enjoyread <<<
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:redeploy (default-cli) @ enjoyread ---
[INFO] Deploying war to http://localhost:8080/enjoyread
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread&update=true
Uploaded: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread&update=true (30550 KB at 18788.0 KB/sec)
[INFO] tomcatManager status code:200, ReasonPhrase:OK
[INFO] FAIL - Deployed application at context path /enjoyread but context failed to start
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:02 min
[INFO] Finished at: 2017-03-30T22:21:30+08:00
[INFO] Final Memory: 20M/237M
[INFO] ------------------
[图片上传中。。。(1)]
存在问题部署(踩过的坑,分享一个存在问题的部署)
步骤一:修改修改tomcat的conf目录下tomcat-users.xml文件,在<tomcat-users>项中添加
<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="12345" roles="manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
步骤二:修改maven的conf目录下settings.xml文件,在<servers>中增加
<server>
<id>tomcat</id>
<username>admin</username>
<password>12345</password>
</server>
这三个字段的值是自己定的
步骤三:配置项目的pom.xml文件,向其中增加如下字段
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat</server>
<username>admin</username>
<password>12345</password>
<path>/enjoyread</path>
</configuration>
</plugin>
其中的字段<server>tomcat</server>,<username>admin</username>,<password>12345</password>的值和maven的conf目录下settings.xml配置的<id>tomcat</id>,<username>admin</username>,<password>12345</password>值对应
步骤四:发布
使用 mvn tomcat:deploy 命令发布
遇到错误
错误一:使用mvn tomcat:deploy出现如下错误
Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.0:deploy (default-cli) on project my-webapp: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fdms&war=
解决方式
1.在maven的conf目录下的settings.xml文件中增加如下字段:
<pluginGroups>
<pluginGroup>org.codehaus.modello</pluginGroup>
</pluginGroups>
2.删除{Path}/.m2\repository\org\apache\tomcat\maven下的文件,然后mvn clean install
3.使用tomcat7:deploy
错误二:在发布项目时,会出现如下错误:
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread
2064/30550 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread
2054/30550 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread
2054/30550 KB
[INFO] I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
[INFO] Retrying request
Uploading: http://localhost:8080/manager/text/deploy?path=%2Fenjoyread
2054/30550 KB
解决方式
使用tomcat7:redeploy代替tomcat:deploy
猜测错误原因:可能是已经发布过项目,tomcat正在占用着原来的项目,可能冲突导致