Cargo-maven2-plugin插件自动部署
来源:互联网 发布:r语言网络爬虫 编辑:程序博客网 时间:2024/06/05 08:12
1、在settings.xml里面的pluginGroups节点增加<pluginGroup>org.codehaus.cargo</pluginGroup>以便命令行调用,然后增加server
2、部署到本地Web容器
If you wish to use Jetty 5.x, you don't have to specify <containerId>
nor <type>
in the <container>
element because Jetty 5x is Cargo's default container.
2.1、standalone模式
在standalone模式,Cargo会从Web容器的安装目录复制一份配置(conf目录)到用户指定的目录,然后在此基础上部署应用,每次重新构建的时候,用户指定目录都会被清空,所有配置被重新生成。
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.4.9</version> <!-- cargo.hostname the remote host name or ip address --> <configuration> <container> <containerId>tomcat7x</containerId>
<!-- Tomcat容器的主目录 --> <home>E:\workspace\richinfo\apache-tomcat\apache-tomcat-7.0.65</home> <log>${project.build.directory}/cargo.log</log> <output>${project.build.directory}/output.log</output> </container> <configuration> <type>standalone</type> <home>${project.build.directory}/tomcat7x</home> <properties> <!-- 更改监听端口 --> <cargo.servlet.port>80</cargo.servlet.port> </properties> </configuration> </configuration></plugin>mvn cargo:run启动
2.2、existing模式
在existing模式下,用户需要指定现有的web容器配置目录,然后Cargo会直接使用这些配置并将应用部署到其对应的位置。相当于替代人为部署到web容器中,即使web容器处于未运行状态。
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.4.9</version>
<configuration> <container> <containerId>tomcat7x</containerId> <home>E:\workspace\richinfo\apache-tomcat\apache-tomcat-7.0.65</home> <log>${project.build.directory}/cargo.log</log> <output>${project.build.directory}/output.log</output> </container> <configuration> <type>existing</type> <home>E:\workspace\richinfo\apache-tomcat\apache-tomcat-7.0.65</home> </configuration> </configuration>
</plugin>运行cargo:run之后在对应的tomcat的webapps目录下能够看到被部署的应用。
3、部署到远程Web容器
注意在远程部署模式下,Container元素的type子元素的值必须为remote,如果不指定,Cargo会默认使用installed,并寻找对应的容器安装目录或者安装包,一般我们远程部署的服务器上都有设定好的web容器了,并不需要再区安装。远程部署实现方式依靠web容器提供的管理部署功能。
3.1、在tomcat7的conf/tomcat-users.xml中增加角色和用户, 不然会报403,没法访问
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <user username="admin" password="password" roles="admin-gui,manager-gui,manager-script,manager-status"/>3.2、配置pom.xml文件
<!-- Cargo插件,快速自动化部署到Web容器 --> <!-- container标签中:--> <!--standalone: CARGO will create the configuration folder using your properties--> <!--existing: an existing configuration folder, for example that you would have manually generated, will be used--> <!--runtime: not applicable for an embedded container--> <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.4.9</version> <configuration> <container> <containerId>tomcat7x</containerId> <type>remote</type> <log>${project.build.directory}/cargo.log</log> <output>${project.build.directory}/output.log</output> </container> <configuration> <type>runtime</type> <properties> <!-- 部署远程时指定 username password --> <cargo.protocol>http</cargo.protocol> <cargo.servlet.port>9004</cargo.servlet.port> <cargo.hostname>127.0.0.1</cargo.hostname> <cargo.remote.username>deploy</cargo.remote.username> <cargo.remote.password>deploy</cargo.remote.password> </properties> </configuration> <!--<deployables>--> <!--<deployable>--> <!--<groupId>io.steveguoshao</groupId>--> <!--<artifactId>webapp</artifactId>--> <!--<type>war</type>--> <!--<properties>--> <!--<context>/${project.artifactId}</context>--> <!--</properties>--> <!--<!– 可选:验证是否部署成功 –>--> <!--<!–<pingURL>http://192.168.18.247:9004/webapp</pingURL>–>--> <!--<!– 可选:验证超时时间,默认是120000 毫秒–>--> <!--<!–<pingTimeout>60000</pingTimeout>–>--> <!--</deployable>--> <!--</deployables>--> </configuration> <executions> <execution> <id>verify-deployer</id> <phase>package</phase> <goals> <goal>deployer-redeploy</goal> </goals> </execution> <execution> <id>clean-deployer</id> <phase>clean</phase> <goals> <goal>deployer-undeploy</goal> </goals> </execution> </executions> </plugin>
Cargo插件中各个命令的之间的异同
Goals
Description
cargo:start
Start a container. That goal will:
- If the plugin configuration requires so, installs the container.
- If the plugin configuration defines a container with a standalone local configuration, it will create the configuration.
- If the plugin configuration contains one or more deployables, it will deploy these to the container automatically.
- If the plugin configuration contains no deployables but the project's packaging is Java EE (WAR, EAR, etc.), it will deploy the project's deployable to to the container automatically.
- And, of course, start the container.
Note: A container that's started with cargo:start
will automatically shut down as soon as the parent Maven instance quits (i.e., you see a BUILD SUCCESSFUL
or BUILD FAILED
message). If you want to start a container and perform manual testing, see our next goal cargo:run
.
cargo:run
Start a container and wait for the user to press CTRL + C
to stop. That goal will:
- If the plugin configuration requires so, installs the container.
- If the plugin configuration defines a container with a standalone local configuration, it will create the configuration.
- If the plugin configuration contains one or more deployables, it will deploy these to the container automatically.
- If the plugin configuration contains no deployables but the project's packaging is Java EE (WAR, EAR, etc.), it will deploy the project's deployable to to the container automatically.
- And, of course, start the container and wait for the user to press
CTRL + C
to stop.
cargo:stop
Stop a container.
cargo:restart
cargo:restart
, it will simply be started.cargo:configure
Create the configuration for a local container, without starting it. Note that the cargo:start
and cargo:run
goals will also install the container automatically (but will not call cargo:install
).
cargo:package
Package the local container.
cargo:daemon-start
Start a container via the daemon. Read more on: Cargo Daemon
Note: The daemon:start
goal is actually equivalent to a restart in CARGO's terms; in the case a container with the same cargo.daemon.handleid
already exists then it will be stopped first before your container is started. This also implies that in the case the new container fails to start, the old one will not be restarted.
cargo:daemon-stop
Stop a container via the daemon. Read more on: Cargo Daemoncargo:deployer-deploy
(aliased to cargo:deploy
)
Deploy a deployable to a running container.
Note: The cargo:start
and cargo:run
do already deploy the deployables specified in the configuration to the container; as a result calling cargo:deploy
for a container which has been started by CARGO in the same Maven2/Maven3 project will most likely cause a second deployment of the same deployables (and might even fail).
cargo:deployer-undeploy
(aliased to cargo:undeploy
)
Undeploy a deployable from a running container.
cargo:deployer-start
Start a deployable already installed in a running container.
cargo:deployer-stop
Stop a deployed deployable without undeploying it.
cargo:deployer-redeploy
(aliased to cargo:redeploy
)
Undeploy and deploy again a deployable. If the deployable was not deployed before calling cargo:deployer-redeploy
(or its alias cargo:redeploy
) it will simply be deployed.
cargo:uberwar
Merge several WAR files into one.
cargo:install
Installs a container distribution on the file system. Note that the cargo:start
goal will also install the container automatically (but will not call cargo:install
).
cargo:help
Get help (list of available goals, available options, etc.).
从上面可以看出,cargo:start于cargo:run的不同之处了吧?cargo:start的生命周期依赖于maven实例的生命周期,也就是说,maven构建成功或者失败之后,cargo插件的生命周期也自动停止了;而cargo:run不同,不管maven是否构建成功或者失败,都必须手工去按Ctrl + C来停止。
参考资料:
1.徐文斌的《Maven实战》
2.http://cargo.codehaus.org/Maven2+Plugin+Reference+Guide
3.http://cargo.codehaus.org/Maven2+plugin
4.http://cargo.codehaus.org/Deploying+to+a+running+container
5.https://codehaus-cargo.github.io/cargo/Starting+and+stopping+a+container.html
- Cargo-maven2-plugin插件自动部署
- cargo, maven插件cargo实现自动部署
- 使用cargo-maven2-plugin插件自动化发布到Tomcat服务器
- maven2之m2eclipse使用手册之七通用容器插件cargo-maven2-plugin
- 利用Maven2的插件方式通过Cargo来远程部署应用到Jboss7上
- cargo自动部署
- 利用maven插件cargo远程(本地)自动部署
- mvn cargo 远程自动部署
- 使用Maven插件Cargo实现自动化部署
- maven项目使用cargo自动部署:
- 基于maven-cargo-plugin 的tomcat7.x热部署记录
- 使用wagon-maven-plugin插件自动部署项目
- 使用wagon-maven-plugin插件自动部署项目
- 使用Maven Cargo 插件管理Tomcat6的部署
- 用cargo插件部署war包,并支持debug
- 使用Maven Cargo 插件管理Tomcat6的部署
- 用cargo插件部署war包,并支持debug
- 使用Maven Cargo 插件管理Tomcat的部署
- 农历闰年闰月表
- vue学习之路 一 (初期搭建vue项目)
- Fragment通讯
- ORACLE 中ROWNUM用法总结! (转)
- C#文件上传同时附带参数上传
- Cargo-maven2-plugin插件自动部署
- 开发环境、生产环境、测试环境的基本理解和区别
- Angularjs Filter
- log4j简单配置总结
- sql语句的执行顺序和别名问题
- LINUX 学习
- Java工具类--List<T>带出excel
- 对话美团 CEO 王兴:太多人关注边界,而不关注核心
- 压缩感知学习