Apache Maven Cargo deploy with Tomcat 7

3 篇文章 0 订阅

Following the post about Deploy to Tomcat 6 using Maven, here is a ready to use example with the main differences explained in the table below

 Tomcat 7Tomcat 6
containerId<containerId>tomcat7x</containerId><containerId>tomcat6x</containerId>
Url of Tomcat manager<cargo.remote.uri><cargo.tomcat.manager.url>
examplehttp://host..com/manager/text/http://host..com/manager/
tomcat-users.xml

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script"/>
</tomcat-users>

<tomcat-users>
  <role rolename="manager"/>
  <user username="admin" password="admin" roles="manager"/>
</tomcat-users>

And finally a snippet of an Apache Maven pom.xml ready to use in a profile, so you can reuse this profile like a method call

<profile>
 <id>deployTomcat</id>
<activation>
  <activeByDefault>false</activeByDefault>
</activation>
<build>
 <plugins>
    <plugin>
     <groupId>org.codehaus.cargo</groupId>
     <artifactId>cargo-maven2-plugin</artifactId>
     <version>1.1.0</version>
    <configuration>
     <wait>true</wait>
     <container>
      <containerId>tomcat7x</containerId>
      <type>remote</type>
     </container>
     <configuration>
      <type>runtime</type>
      <properties>
       <cargo.remote.uri>
         ${tomcat.url}
       </cargo.remote.uri>
       <cargo.remote.username>
          ${tomcat.user}     
       </cargo.remote.username>
        <cargo.remote.password>
          ${tomcat.pwd}
        </cargo.remote.password>
      </properties>
      </configuration>
      <deployer>
       <type>remote</type>
       <deployables>
       <deployable>
        <groupId>${deploy.groupid}</groupId>
        <artifactId>${deploy.artifactid}</artifactId>
        <type>war</type>
        <properties>
         <context>${deploy.context}</context>
        </properties>
       </deployable>
      </deployables>
     </deployer>
    </configuration>
    <executions>
     <execution>
      <id>verify-deploy</id>
      <phase>pre-integration-test</phase>
      <goals>
       <goal>deployer-undeploy</goal>
       <goal>deployer-deploy</goal>
      </goals>
     </execution>
    </executions>
    </plugin>
 </plugins>
</build>
</profile>

Place as many profiles as you have machine to deploy in settings.xml and declare some variables as properties, as shown below:

<profile>
 <id>serverA</id>
 <activation>
    <activeByDefault>false</activeByDefault>
 </activation>
 <properties>
    <tomcat.url>http://host.com/manager/text</tomcat.url>
    <tomcat.user>admin</tomcat.user>
    <tomcat.pwd>admin</tomcat.pwd>
    <!-- these properties must be defined
       as system property or -D -->
    <!-- - deployable.artifactid:
         artifactId of web application to be deployed -->
    <!-- - deployable.context: web context name -->
 </properties>
</profile>

So you can run, and traget multiple host by just exchanging the name of the profile serverA to something else.

mvn integration-test –PdeployTomcat,serverA
   –Ddeployable.artifactid=demo
   -Ddeploy.groupid=com.mycompany
   –Ddeployable.context=showcase

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值