使用Maven自动部署Tomcat 6和Tomcat 7下Web应用
- 开启Tomcat远程管理权限
在tomcat的config目录下的tomcat-users.xml文件,
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
不多说,此处多给些权限,别小气,否则容易没有权限进行部署(tomcat给的原始配置示例都被<!---->注释掉了)。配置是否成功的验证方法是重启Tomcatà登陆tomcat管理控制台à输入用户名密码后(admin/admin)à部署一个war应用试试,成功则OK,不成功就不要往下走了。
- 配置tomcat6- maven - plugin 或 tomcat7- maven - plugin
工程 POM 中,配置插件 :
Tomcat 6的配置示例如下:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://16.158.165.0:8080/manager</url><!-- http://127.0.0.1:8080/manager-->
<username>admin</username>
<password>admin</password>
<path>/BizService</path><!--WEB应用上下文路径-->
</configuration>
</plugin>
Tomcat 7的配置示例如下:(注意红色高亮部分差异)
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://16.158.165.0:8080/manager/text</url>
<username>admin</username>
<password>admin</password>
<path>/BizService</path><!--WEB应用上下文路径-->
</configuration>
</plugin>
- 部署相关命令
Tomcat 6部署及重新部署命令
mvn tomcat6:deploy
mvn tomcat6:redeploy
Tomcat 7部署及重新部署命令
mvn tomcat7:deploy
mvn tomcat7:redeploy
- 备注
m2eclipse也是如此配置。
<username><password>也可以用<server>方式配置,就是在setting文件中配置用户名密码,POM中只是指定server id,此处不详述。
- 详细信息(来自官网2.3版本)
Goal |
Description |
Deploy a WAR to Tomcat. |
|
Deploy a WAR to Tomcat without forking the package lifecycle. |
|
Deploy an exploded WAR to Tomcat. |
|
Display help information on tomcat6-maven-plugin.
|
|
Lists information about the Tomcat version, OS, and JVM properties. |
|
Deploy a WAR in-place to Tomcat. |
|
Lists all the currently deployed web applications in Tomcat. |
|
Redeploy a WAR in Tomcat. (Alias for the deploy goal with its update parameter set to true.) |
|
Redeploy a WAR in Tomcat without forking the package lifecycle. (Alias for the deploy-only goal with its update parameter set to true.) |
|
Reload a WAR in Tomcat. |
|
Lists JNDI resources in Tomcat. |
|
Lists security roles in Tomcat. |
|
Runs the current project as a dynamic web application using an embedded Tomcat server. |
|
Runs the current project as a packaged web application using an embedded Tomcat server. |
|
Same as run-war goal without forking the package cycle. |
|
Lists session information for a WAR in Tomcat. |
|
Shuts down all possibly started embedded Tomcat servers. This will be automatically done through a shutdown hook or you may call this Mojo to shut them down explictly.
By default the
|
|
Start a WAR in Tomcat. |
|
Stop a WAR in Tomcat. |
|
Undeploy a WAR from Tomcat. |