Deploy to Tomcat 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 Tomcat (for example), add the following to your pom.xml:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
        <wait>false</wait>
        <container>
            <containerId>tomcat5x</containerId>
            <zipUrlInstaller>
                <url>
http://www.apache.org/dist/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.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>

I need to investigate whether or not Cargo will allow hot deploy to Tomcat.

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

Leave a Reply