Cargo是一组帮助用户操作Web容器的工具,它能帮助用户实现自动化部署,而且它几乎支持所有的Web容器,如Tomcat、JBoss、Jetty和Glassfish。Cargo通过cargo-maven2-plugin提供了Maven集成,Maven用户可以使用该插件将Web项目部署到Web容器中。
Cargo支持两种供本地部署方式,一种远程部署方式,本地部署分为standalone模式和existing模式。
在standalone模式中,Cargo会从Web容器的安装目录复制一份配置到用户指定的目录,并且部署应用。
在existing模式中,用户需要指定现有的Web容器配置目录,然后Cargo会直接使用这些配置并将应用部署到其对应的位置。
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<container>
<containerId>tomcat7x</containerId> <!-- 容器类型 -->
<home>D:\apache-tomcat-7.0.59</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/apache-tomcat-7.0.59</home>
<properties>
<cargo.jvmargs>
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8887
</cargo.jvmargs>
</properties>
</configuration>
</configuration>
</plugin>
默认情况下,Cargo会让Web容器监听8080端口,可以通过修改Cargo的cargo.servlet.port属性来改变这一配置,下面是existing类型的配置,表示使用本地tomcat部署:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<home>D:\apache-tomcat-7.0.59</home>
</container>
<configuration>
<type>existing</type>
<home>D:\apache-tomcat-7.0.59</home>
</configuration>
</configuration>
</plugin>
部署应用至远程Web容器
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargp.remote.username>username</cargp.remote.username>
<cargp.remote.password>password<cargp.remote.password>
<cargp.tomcat.manager.url><cargp.tomcat.manager.url>
</properties>
</configuration>
</configuration>
</plugin>
对于远程部署的方式来说,container元素的type子元素的值必须为remote。如果不显式指定,Cargo会使用默认值installed,并寻找对应容器安装目录或者安装包。configuration中的type子元素值为runtime,表示既不使用独立的容器配置,也不实用本地现有的容器配置,而是依赖于一个已运行的容器,properties元素用来声明一些容器热部署相关的配置。例如,这里的Tomcat7就需要提供用户名、密码以及管理地址。