1

I have a project with a Maven Cargo plugin configuration shown below. When I run mvn cargo:redeploy, it deploys the current version of the application to server at AAA.BBB.CCC.DDD.

Now I want to add a second server, say EEE.FFF.GGG.HHH. EEE.FFF.GGG.HHH will be the production server and AAA.BBB.CCC.DDD - the development/test stage.

Is it possible to use mvn cargo:redeploy to deploy the application to different servers (production and test, EEE.FFF.GGG.HHH and AAA.BBB.CCC.DDD) ? If yes, how should I modify Cargo's plugin configuration below?

<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>
Fabien
  • 859
  • 6
  • 15
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • that should be possible using executions within the configuration. you can add multiple executions, just make sure they have a different id. The pom reference: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html contains some examples. – wemu Jan 05 '15 at 09:38

1 Answers1

1

As indicated by @wemu, you can put many executions in your plugin configuration as following :

<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>

And you can even mutualize some configuration elements outside of the executions like that if you need to add more executions you just have to change the user password and IP adress :

<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>
Fabien
  • 859
  • 6
  • 15