使用Maven自动部署Tomcat 6和Tomcat 7下Web应用

系统 1670 0

使用Maven自动部署Tomcat 6和Tomcat 7下Web应用

  1. 开启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,不成功就不要往下走了。

 

  1. 配置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>

 

  1. 部署相关命令

Tomcat 6部署及重新部署命令

mvn tomcat6:deploy

mvn tomcat6:redeploy

 

Tomcat 7部署及重新部署命令

mvn tomcat7:deploy

mvn tomcat7:redeploy

 

  1. 备注

m2eclipse也是如此配置。

<username><password>也可以用<server>方式配置,就是在setting文件中配置用户名密码,POM中只是指定server id,此处不详述。

 

  1. 详细信息(来自官网2.3版本)

Goal

Description

tomcat6:deploy

Deploy a WAR to Tomcat.

tomcat6:deploy-only

Deploy a WAR to Tomcat without forking the package lifecycle.

tomcat6:exploded

Deploy an exploded WAR to Tomcat.

tomcat6:help

Display help information on tomcat6-maven-plugin.
Call  mvn tomcat6:help -Ddetail=true -Dgoal=<goal-name>  to display parameter details.

tomcat6:info

Lists information about the Tomcat version, OS, and JVM properties.

tomcat6:inplace

Deploy a WAR in-place to Tomcat.

tomcat6:list

Lists all the currently deployed web applications in Tomcat.

tomcat6:redeploy

Redeploy a WAR in Tomcat. (Alias for the deploy goal with its update parameter set to true.)

tomcat6:redeploy-only

Redeploy a WAR in Tomcat without forking the package lifecycle. (Alias for the deploy-only goal with its update parameter set to true.)

tomcat6:reload

Reload a WAR in Tomcat.

tomcat6:resources

Lists JNDI resources in Tomcat.

tomcat6:roles

Lists security roles in Tomcat.

tomcat6:run

Runs the current project as a dynamic web application using an embedded Tomcat server.

tomcat6:run-war

Runs the current project as a packaged web application using an embedded Tomcat server.

tomcat6:run-war-only

Same as run-war goal without forking the package cycle.

tomcat6:sessions

Lists session information for a WAR in Tomcat.

tomcat6:shutdown

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  shutdown  goal is not bound to any phase. For integration tests you might want to bind it to post-integration-test .

tomcat6:start

Start a WAR in Tomcat.

tomcat6:stop

Stop a WAR in Tomcat.

tomcat6:undeploy

Undeploy a WAR from Tomcat.

使用Maven自动部署Tomcat 6和Tomcat 7下Web应用


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论