MAVEN專案部署到tomcat7問題
3.403錯誤
報錯資訊如下:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Fhelloworld -> [Help 1]
因為使用是Tomcat7產生了問題,很是糾結
1)如果使用的是Tomcat 7,需要修改pom.xml中部署的url地址,將<url>http://localhost:8080/manager</url>改<url>http://localhost:8080/manager/text</url>
2)給tomcat使用者許可權分配上,需要同時具備manager-gui和manager-script許可權,我在遇到該問題時,就是忘了分配manager-script許可權。
正確的conf/tomcat-users.xml配置應為:
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin” password="admin" roles="manager-gui, manager-script"/>
</tomcat-users>
在查詢問題的時候也發現了兩種經常錯誤,再次記錄一下
1.Connection refused錯誤
報錯資訊如下:
[ERROR]Failed to execute goal org.apache.tomcat.maven: tomcat7-maven-plugin: 2.0- SNAPSHOT: deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
原因:未啟動Tomcat伺服器
解決辦法:先啟動Tomcat伺服器再選擇Run
2. 401錯誤
報錯資訊如下:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin: 2.0-SNAPSHOT:deploy (default-cli) on project helloworld: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/text/deploy?path=%2Fhelloworld -> [Help 1]
原因:許可權問題
解決辦法在$CATALINA_BASE/conf/tomcat-users.xml,
如D:\apache-tomcat-7.0.34\conf\tomcat-users.xml檔案中新增許可權
<role rolename=”manager”/>
<user username=”admin” password=”admin” roles=”manager”/>
修改pom.xml檔案,在<configuration> </configuration>中新增
<username>admin</username> <password>admin</password>