tomcat7 需要使用 tomcat-maven-plugin 的新版本,版本支持tomcat6和tomcat7,groupId也由org.codehaus.mojo改为org.apache.tomcat.maven.
1、配置tomcat的环境变量
如:CATALINA_HOME=此处填写comcat的物理地址
2、给comcat配置用户
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="admin" roles="manager-gui, manager-script"/>
3、配置maven的setting.xml文件,地址 %MAVEN_HOME%\conf\setting.xml
此处的MAVEN_HOME是maven的安装地址。
在<servers>标签中加入
<server>
<id>tomcat</id>
<username>admin</username>
<password>admin</password>
</server>
4、修改工程的pom.xml
添加 tomcat-maven-plugin插件信息
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>tomcat</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>tomcat</server>
</configuration>
</plugin>
</plugins>
</pluginManagement>
--html可以替换成text
添加以下tomcat-maven-plugin插件
<repository> <id>people.apache.snapshots</id> <url> http://repository.apache.org/content/groups/snapshots-group/ </url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository>
<pluginRepository> <id>apache.snapshots</id> <name>Apache Snapshots</name> <url> http://repository.apache.org/content/groups/snapshots-group/ </url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository>
5、 启动tomcat,在工程或pom.xml上右键,maven build的goals中输入命令tomcat7:deploy即可发布 , 或在Run Configurations->Maven build新建一个命令,base directory里选择你的web project,在Goals栏可填写你所需要的命令。
参考:
http://www.cnblogs.com/qq78292959/p/3711497.html