这两天想在eclipse上运行maven web项目,折腾了许久,总算success啦。
1,利用eclipse创建dynamic web project(eclipse需要安装m2eclipse).
步骤如下图:
2,创建完project后修改pom文件
Right Click >> Run As >> Maven Build,在窗口中的Goals内输入:package tomcat:redeploy, click "run"控制台出现结果:BUILD FAILURE, 出现“[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy ”,解决办法:
修改pom文件,绿色为添加内容:
<build>
<finalName>project</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<path>/project</path>
<server>tomcat</server>
<username>admin</username>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
3,修改tomcat-users文件(tomcat_home/conf/tomcat-users.xml),添如如下内容:
<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="password" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
4,修改maven的setings文件(maven_home/conf/settings.xml),添加如下内容:
<server>
<id>tomcat</id>
<username>admin</username>
<password>password</password>
</server>
在再次运行,令人兴奋的BUILD SUCCESS出现啦,:)~
可能会出现Connection refused,401和403问题,分别是由于tomcat未启动和tomcat的权限问题.