項(xiàng)目環(huán)境
tomcat7 和maven3.3.9
正確部署過(guò)程
步驟一:修改修改tomcat的conf目錄下tomcat-users.xml文件,在<tomcat-users>項(xiàng)中添加
<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>
這三個(gè)字段的值是自己定的
2.在<pluginGroups>字段中添加
<pluginGroup>org.codehaus.modello</pluginGroup>
步驟三:配置項(xiàng)目的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>值對(duì)應(yīng)
步驟四:發(fā)布
使用 mvn tomcat7:deploy 命令發(fā)布
配置成功結(jié)果
[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)]
存在問(wèn)題部署(踩過(guò)的坑,分享一個(gè)存在問(wèn)題的部署)
步驟一:修改修改tomcat的conf目錄下tomcat-users.xml文件元媚,在<tomcat-users>項(xiàng)中添加
<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>
這三個(gè)字段的值是自己定的
步驟三:配置項(xiàng)目的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>值對(duì)應(yīng)
步驟四:發(fā)布
使用 mvn tomcat:deploy 命令發(fā)布
遇到錯(cuò)誤
錯(cuò)誤一:使用mvn tomcat:deploy出現(xiàn)如下錯(cuò)誤
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
錯(cuò)誤二:在發(fā)布項(xiàng)目時(shí)炭晒,會(huì)出現(xiàn)如下錯(cuò)誤:
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
猜測(cè)錯(cuò)誤原因:可能是已經(jīng)發(fā)布過(guò)項(xiàng)目,tomcat正在占用著原來(lái)的項(xiàng)目甥角,可能沖突導(dǎo)致