【问题标题】:Can I use Maven Cargo plugin to deploy a WAR to 2 different servers (production and dev stages)?我可以使用 Maven Cargo 插件将 WAR 部署到 2 个不同的服务器(生产和开发阶段)吗?
【发布时间】:2015-03-02 19:38:39
【问题描述】:

我有一个项目,其 Maven Cargo 插件配置如下所示。当我运行mvn cargo:redeploy 时,它将应用程序的当前版本部署到AAA.BBB.CCC.DDD 的服务器。

现在我想添加第二个服务器,比如EEE.FFF.GGG.HHHEEE.FFF.GGG.HHH 将是生产服务器,AAA.BBB.CCC.DDD - 开发/测试阶段。

是否可以使用mvn cargo:redeploy 将应用程序部署到不同的服务器(生产和测试,EEE.FFF.GGG.HHHAAA.BBB.CCC.DDD)?如果是,我应该如何修改 Cargo 下面的插件配置?

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>my-product</artifactId>
    <packaging>war</packaging>
    <version>[...]</version>
    <name>my-product</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <powermock.version>1.5</powermock.version>
    </properties>

    <build>
        <finalName>${project.artifactId}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.3.3</version>
                <configuration>
                    <container>
                        <containerId>tomcat7x</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.remote.username>user name</cargo.remote.username>
                            <cargo.remote.password>password</cargo.remote.password>
                            <cargo.hostname>AAA.BBB.CCC.DDD</cargo.hostname>
                            <cargo.protocol>http</cargo.protocol>
                            <cargo.servlet.port>8080</cargo.servlet.port>
                        </properties>
                    </configuration>

                    <!-- Deployer configuration -->
                    <deployer>
                        <type>remote</type>
                    </deployer>
                    <deployables>
                        <deployable>
                            <groupId>com.mycompany</groupId>
                            <artifactId>my-product</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>

【问题讨论】:

标签: maven maven-3 maven-cargo cargo-maven2-plugin


【解决方案1】:

正如@wemu 所指出的,您可以在插件配置中放置许多执行,如下所示:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>

        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
        </deployer>
        <deployables>
            <deployable>
                <groupId>com.mycompany</groupId>
                <artifactId>my-product</artifactId>
                <type>war</type>
            </deployable>
        </deployables>
    </configuration>
    <executions>
        <!-- First execution to deploy on AAA.BBB.CCC.DDD -->
        <execution>
            <id>deploy1</id>
            <configuration>
                <type>runtime</type>
                <properties>
                    <cargo.remote.username>user name 1</cargo.remote.username>
                    <cargo.remote.password>password 1</cargo.remote.password>
                    <cargo.hostname>AAA.BBB.CCC.DDD</cargo.hostname>
                    <cargo.protocol>http</cargo.protocol>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                </properties>
            </configuration>
        </execution>
        <!--  Second execution to deploy on EEE.FFF.GGG.HHH -->
        <execution>
            <id>deploy2</id>
            <configuration>
                <type>runtime</type>
                <properties>
                    <cargo.remote.username>user name 2</cargo.remote.username>
                    <cargo.remote.password>password 2</cargo.remote.password>
                    <cargo.hostname>EEE.FFF.GGG.HHH</cargo.hostname>
                    <cargo.protocol>http</cargo.protocol>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

您甚至可以在 executions 之外共享一些配置元素,例如,如果您需要添加更多执行,您只需更改用户密码和 IP 地址:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>

        <!-- Common configuration -->
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.protocol>http</cargo.protocol>
                <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
        </configuration>

        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
        </deployer>
        <deployables>
            <deployable>
                <groupId>com.mycompany</groupId>
                <artifactId>my-product</artifactId>
                <type>war</type>
            </deployable>
        </deployables>
    </configuration>
    <executions>
        <!-- First execution to deploy on AAA.BBB.CCC.DDD -->
        <execution>
            <id>deploy1</id>
            <configuration>
                <properties>
                    <cargo.remote.username>user name 1</cargo.remote.username>
                    <cargo.remote.password>password 1</cargo.remote.password>
                    <cargo.hostname>AAA.BBB.CCC.DDD</cargo.hostname>
                </properties>
            </configuration>
        </execution>
        <!--  Second execution to deploy on EEE.FFF.GGG.HHH -->
        <execution>
            <id>deploy2</id>
            <configuration>
                <properties>
                    <cargo.remote.username>user name 2</cargo.remote.username>
                    <cargo.remote.password>password 2</cargo.remote.password>
                    <cargo.hostname>EEE.FFF.GGG.HHH</cargo.hostname>
                </properties>
            </configuration>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2012-09-26
    • 2012-03-15
    • 2012-04-02
    • 2014-05-30
    相关资源
    最近更新 更多