本文主要是介绍【maven实战】41-使用cargo-maven2-plugin实现自动化部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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支持两种本地部署的方式,分别是standalone模式和existing模式。
在standalone模式中,Cargo会从Web容器的安装目录复制一份配置到用户指定的目录,然后在此基础上部署应用,每次重新构建的时候,这个目录都会被清空,所有的配置重新生成。
而在existing模式中,用户需要指定现有的Web容器配置目录,然后Cargo会直接使用这些配置并将应用部署到对应的位置。
standalone配置样例:
<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.29</home></container><configuration><type>standalone</type><home>${project.build.directory}/tomcat6x</home><properties><cargo.servlet.port>8080</cargo.servlet.port></properties></configuration></configuration></plugin>
Cargo默认端口为8080可以通过properties元素加入cargo.servlet.port属性改变大u你口号,cargo-maven2-plugin不是maven默认插件,需要将其添加到settings.xml的pluginGroup元素以方便命令行使用。
现在要让Cargo启动tomcat并部署应用,只需要运行:
mvn cargo:start
要将应用直接部署到现有的Web容器下,需要配置Cargo使用existing模式,如下:
<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.29</home></container><configuration><type>existing</type><home>D:\devware\apache-tomcat-6.0.29</home><properties><cargo.servlet.port>8080</cargo.servlet.port></properties></configuration></configuration></plugin>
部署至远程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>admin123</cargo.remote.password><cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url></properties></configuration></configuration></plugin>
对于远程部署方式来说,container元素的type子元素的值必须为remote。
有了上述配置后,可以使用如下命令让Cargo部署应用了:
mvn cargo:redeploy
如果容器中已经部署了当前应用,Cargo会先将其卸载,然后在重新部署。
这篇关于【maven实战】41-使用cargo-maven2-plugin实现自动化部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!