1.run as maven clean
清除原有的编译结果重新编译一次。
2.run as maven bulid..
goals:package tomcat7:deploy
打包到Tomcat7
报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project maven: Fatal error compiling: tools.jar not found: C:\eclipse\jre\..\lib\tools.jar
解决办法:
点击Eclipse菜单:Window->Preferences->Java->Installed JREs,选择右侧的Edit来修改JREs,之前我的JRE home设置的是:C:\Program Files\Jave\jre6,这个位置下是没有tools.jar包的,修改成:C:\Program Files\Java\jdk1.6.0_25,然后点击弹出窗口的Finish按钮和主页面中的OK按钮,则问题解决。
报错:Cannot invoke Tomcat manager: Software caused connection abort: socket write error
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>
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]
原因:产生该问题有可能因为两个原因,具体参见解决办法
解决办法:
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>
错误参考地址:http://www.51testing.com/html/94/488194-845177.html
非常感谢前辈怂小猫的分享!
最终conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager"/>
<user username="admin" password="admin" roles="manager-gui,admin-gui"/>
<user username="admin" password="admin" roles="manager-script"/>
<user username="admin" password="admin" roles="manager"/>
最终pom.xml中添加:
1 <build>
2 <plugins>
3 <plugin>
4 <groupId>org.apache.tomcat.maven</groupId>
5 <artifactId>tomcat7-maven-plugin</artifactId>
6 <configuration>
7 <url>http://localhost:8080/manager/text</url>
8 <server>tomcat</server>
9 <username>admin</username>
10 <password>admin</password>
11 <path>/maven</path>
12 </configuration>
13 </plugin>
14 </plugins>
15 </build>
写成:
<url>http://localhost:8080/manager/text</url>
否则没效果 控制台项目下输入:mvn clean tomcat7:redeploy ,总算部署成功了。
附上结果图:
本来是搭建的MavenSSM的demo,先把环境调通,后续再补充完整的项目过程。