概念
Cargo是一组帮助用户操作Web容器的工具,能够实现自动化部署,并且支持几乎所有的Web容器,如Tomcat、JBoss、Jetty和Glassfish等。
Cargo通过cargo-maven2-plugin提供了Maven集成,可以使用该插件将Web项目部署到Web容器中。
cargo-maven2-plugin和jetty-maven-plugin功能相似,但目的不同。cargo-maven2-plugin主要服务于自动化部署,而jetty-maven-plugin主要用来帮助日常的快速开发和测试。
Cargo部署模式说明
cargo支持两种本地部署的方式,分别是standalone模式和existing模式。
standalone模式部署示例
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fengyun.webpro</groupId>
<artifactId>webpro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.0-beta-2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
<build>
<defaultGoal>clean compile</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<home>D:\devware\apache-tomcat-6.0.44</home>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/tomcat6x</home>
<properties>
<cargo.servlet.port>8080</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>
1、打包 package
2、执行命令 cargo:run,首次执行会下载相应的jar包,耐心等待即可
3、成功启动,访问测试
standalone模式部署总结
cargo会从Web容器安装目录复制一份配置到用户指定的目录,然后在此基础上部署应用,每次重新构建的时候,这个目录都会被清空,所有配置被重新生成。
其实就相当于把web容器复制了一份过来,然后再把项目部署到复制过来的容器中。
示例:
1、部署后target目录内容
2、部署后tomcat6x目录内容
3、部署后webapp目录内容
existing模式部署示例
建议更多的使用existing模式,
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<home>D:\devware\apache-tomcat-6.0.44</home>
</container>
<configuration>
<type>existing</type>
<home>D:\devware\apache-tomcat-6.0.44</home>
<properties>
<cargo.servlet.port>8080</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
1、编译、打包
2、打包成功
3、部署至容器,测试,成功
部署至远程Web容器
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<!-- type默认值为installed -->
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<!-- 不同的Web容器,有不同的属性配置,需要查询相关具体的容器配置 -->
<properties>
<cargo.remote.username>admin</cargo.remote.username>
<cargo.remote.password>root</cargo.remote.password>
<cargo.tomcat.manager.url>http://ip:prot/manager</cargo.tomcat.manager.url>
</properties>
</configuration>
</configuration>
</plugin>