Deploy to JBoss using Cargo

The Cargo plugin for Maven has the following uses:

  • to start containers for integration and functional tests
  • to start containers for applications that require a container to be started (Plugins for IDEs, etc)
  • as a framework to manipulate J2EE Module file including container-specific descriptors.
  • to generate container configurations for deployment.

One of the nice things about Cargo is that it can be used to download a container, so that manual installation is not necessary. To configure Cargo to download JBoss (for example), add the following to your pom.xml (under <build><plugins>, not <build><pluginManagement>):

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
        <wait>false</wait>
        <container>
            <containerId>jboss4x</containerId>
            <zipUrlInstaller>
                <url>
                    http://downloads.sourceforge.net/jboss/jboss-4.0.2.zip
                </url>
                <installDir>${installDir}</installDir>
            </zipUrlInstaller>
        </container>
        <configuration>
            <home>
                ${project.build.directory}/jboss4x/container
            </home>
        </configuration>
    </configuration>
</plugin>

You can then run the command

mvn package deploy cargo:start

to fire up the container with your packaged code. It will take a while the first time this is run, as it has to download the zip file from the URL.

mvn cargo:stop

will stop the container.

If you want to use Cargo to start prior to running integration tests, and to stop afterwards, add the following:

<executions>
    <execution>
        <id>start-container</id>
        <phase>pre-integration-test</phase>
        <goals>
            <goal>start</goal>
        </goals>
    </execution>
    <execution>
        <id>stop-container</id>
        <phase>post-integration-test</phase>
        <goals>
            <goal>stop</goal>
        </goals>
    </execution>
</executions>

The Cargo JBoss container also allows for hot deploy. This can be done by simply running the command

mvn package cargo:deploy

while the container is started.

Tip: when combined with How to Skip the Maven ‘test’ Phase, the hot deploy takes a lot less time than running ‘mvn package deploy’ and starting the container manually.

It's only fair to share...
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Leave a Reply