【问题标题】:Using Cargo with Maven to remotely deploy WAR without HOT deployment使用 Cargo 和 Maven 远程部署 WAR 无需 HOT 部署
【发布时间】:2012-04-02 02:39:08
【问题描述】:

我们在构建服务器上使用 Cargo 和 Maven,将 WAR 文件从我们的构建服务器远程部署到内部 QA 服务器进行测试。

我们当前的项目 POM 如下所示,并且适用于热部署。

问题在于而不是热部署,我们希望 Cargo 插件停止 Tomcat 实例,部署新的 WAR,然后启动 Tomcat。有没有办法改变 POM 来管理这种情况?

我们的 Maven 构建定义为:

mvn clean deploy ... cargo:redeploy

以及POM中的cargo插件设置:

                  <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <configuration>
                            <container>
                                <containerId>tomcat7x</containerId>
                                <type>remote</type>
                                <systemProperties>
                                    <cargo.jvmargs>-XX:MaxPermSize=256M -Xmx1024m</cargo.jvmargs>
                                </systemProperties>
                            </container>
                            <configuration>
                                <type>runtime</type>
                                <properties>
                                    <cargo.hostname>qa-server</cargo.hostname>
                                    <cargo.servlet.port>8080</cargo.servlet.port>
                                    <cargo.tomcat.manager.url>http://qa-server:8080/manager</cargo.tomcat.manager.url>
                                    <cargo.remote.username>username</cargo.remote.username>
                                    <cargo.remote.password>pass</cargo.remote.password>
                                </properties>
                            </configuration>
                            <deployer>
                                <type>remote</type>
                                <deployables>
                                    <deployable>
                                        <groupId>com.ourcompany</groupId>
                                        <artifactId>myapp-artifactId</artifactId>
                                        <type>war</type>
                                        <properties>
                                            <context>latest</context>
                                        </properties>
                                    </deployable>
                                </deployables>
                            </deployer>
                        </configuration>
                    </plugin>

【问题讨论】:

  • 热部署会有什么问题?您是否遇到过任何想让货物停止和启动的问题tomcat

标签: java tomcat maven cargo


【解决方案1】:

我们在 Cargo 方面遇到了困难。过了一会儿,tomcat卡住了,不会重启。货物不允许启动/停止tomcat。

所以我们最终做的是放弃货物并使用脚本在远离我们的詹金斯机器的地方重新启动 tomcat。此外,我们在用于部署战争的集成机器上共享一个文件夹。我们还为我们的 conf 文件和文件夹使用 maven 程序集插件。

【讨论】:

    【解决方案2】:

    如何在 build.xml 文件中调用 cleanTomcat ant 任务并遵循以下流程:

    #1. stop, clean container, start
    mvn cargo:stop 
        antrun:run <<<<<<< build.xml file to clean +war +warUnpacked +context.xml
        cargo:start
    
    #2. deploy your webapp
    mvn cargo:deploy
    

    关于unludo 之前的回复,在服务器之间共享文件夹是提高部署阶段速度的好方法。

    您也可以使用maven-clean-plugin(是 mvn clean 之一,但需要额外配置)来清理您的 java 项目之外的目录,即删除您需要在 tomcat 容器中删除的内容。

    【讨论】:

      最近更新 更多