maven发布项目到tomcat的部署

项目环境

tomcat7 和maven3.3.9

正确部署过程

步骤一:修改修改tomcat的conf目录下tomcat-users.xml文件,在项中添加







步骤二:修改maven的conf目录下settings.xml文件

1.在中增加

tomcat
admin
12345

这三个字段的值是自己定的

2.在字段中添加
org.codehaus.modello

步骤三:配置项目的pom.xml文件,向其中增加如下字段


org.apache.tomcat.maven
tomcat7-maven-plugin
2.2

http://localhost:8080/manager/text
tomcat
admin
12345
/enjoyread



org.apache.maven.plugins
maven-shade-plugin
3.0.0





package

shade



其中的字段tomcat,admin,12345的值和maven的conf目录下settings.xml配置的tomcat,admin,12345值对应

步骤四:发布

使用 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文件,在项中添加







步骤二:修改maven的conf目录下settings.xml文件,在中增加


tomcat
admin
12345

这三个字段的值是自己定的

步骤三:配置项目的pom.xml文件,向其中增加如下字段


org.apache.tomcat.maven
tomcat7-maven-plugin
2.2

http://localhost:8080/manager/text
tomcat
admin
12345
/enjoyread

其中的字段tomcat,admin,12345的值和maven的conf目录下settings.xml配置的tomcat,admin,12345值对应

步骤四:发布

使用 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文件中增加如下字段:

org.codehaus.modello

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正在占用着原来的项目,可能冲突导致

你可能感兴趣的:(maven发布项目到tomcat的部署)