1.相关环境变量
idea tomcat8 maven3
2.增加tomcat user, 修改 $CATALINA_HOME/conf/tomcat-users.xml
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager"/>
<user username="test" password="test" roles="manager,manager-gui,manager-script"/>
</tomcat-users>
3.配置maven, 修改 $M2_HOME/conf/settings.xml, 让maven访问tomcat
<servers>
<!-- 配置tomcat 访问权限 -->
<server>
<id>test-tomcat</id>
<username>test</username>
<password>test</password>
</server>
</servers>
4.修改项目pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.hosts>localhost:8080</tomcat.hosts>
</properties>
<build>
<finalName>testApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>test-tomcat</server>
<path>/${project.build.finalName}</path>
<update>true</update>
<url>http://${tomcat.hosts}/manager/text</url>
<!-- war文件路径缺省情况下指向target -->
<!--<warFile>${basedir}/target/${project.build.finalName}.war</warFile>-->
</configuration>
</plugin>
</plugins>
</build>
5.部署命令, 进入项目module目录(pom.xml所在目录)
$ mvn clean:install
$ mvn tomcat7:redeploy # 首次发布 tomcat7:deploy,再次发布 tomcat7:redeploy
6.相关Goals
参考Context Goals
6.1 重新部署war项目
# 部署相关 war 项目
> mvn package tomcat6/7:redeploy
> mvn war:exploded tomcat6/7:redeploy
> mvn war:inplace tomcat6/7:redeploy
# 部署context.xml
> mvn tomcat6/7:redeploy
6.2 卸载 war 项目
> mvn tomcat6/7:undeploy
6.3 启动 war 项目
> mvn tomcat6:start
6.4 停止 war 项目
> mvn tomcat6:stop
6.5 统计session
> mvn tomcat6:sessions