maven构建项目自动部署到tomcat中遇到的各种sb问题总结
maven构建项目自动部署到tomcat中遇到的各种sb问题总结
苦逼的人每天都能遇到苦逼的问题,把这些问题记录下来,等你们来了就不苦逼了!也算积德行善。。
本教程主要解决两个问题:(主要是部署到Tomcat 6.x 和 Tomcat 7.x也有区别,请各自座号入座.)
1.苦逼的401问题
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy(default-cli) on project my_struts: Cannot invoke Tomcat manager: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/deploy?path=%2Fmy_struts&war= -> [Help 1]
2.苦逼的403错误
maven 403 No server username specified - using default Cannot invoke Tomcat manager: Server rened HTTP response code: 403 for URL
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy(default-cli) on project my_struts: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fframework&war=
INFO] Deploying war to http://localhost:8080/report
[DEBUG] No server username specified - using default
解决方案:
1.对于苦逼的401问题和403问题,这个问题是因为你的tomcat里面木有写权限,还有你的pom.xml配置的不对。
<!-- 以下是Tomcat 7.x 系列-->
C:\tomcat\apache-tomcat-7.0.34\conf\tomcat-users.xml文件打开,添加用户和密码
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="pass!@#" roles="manager,manager-gui,admin-gui,manager-script"/>
</tomcat-users>
<!-- 以下是Tomcat 6.x 系列-->
C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="pass!@#" roles="admin,manager,manager-gui,admin-gui,manager-script"/>
</tomcat-users>
C:\Documents and Settings\Administrator\.m2\settings.xml 文件打开,写入用户名和密码
<servers>
<server>
<id>tomcat</id>
<username>admin</username>
<password>pass!@#</password>
</server>
</servers>
D:\workspaces\你的项目目录\pom.xml文件打开,写入配置信息
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<server>tomcat</server><!-- 这个server标签里面的值(tomcat)要和你的setting.xml里面的id的值(tomcat)一致-->
<username>admin</username>
<password>pass!@#</password>
<!-- Tomcat 7.x -->
<url>http://localhost:8080/manager/text</url>
<!-- Tomcat 6.x
<url>http://localhost:8080/manager</url>
-->
<!-- 这个(http://localhost:8080/manager/)是你的tomcat管理地址,如果使用Tomcat 7.x后面的/text要加上,如果使用Tomcat 6.x就不要加了,不要写/html,这个就是解决403苦逼问题的-->
<path>/report</path>
</configuration>
</plugin>