Tutorial: Configure the Cargo deployment plugin

aus eecoo wiki, der freien Wissensdatenbank

There is a cool plugin for Maven called Cargo which simplifies deployment on different servlet container massively. With Cargo you can manage different containers which are installed, start, stop fully automatic. Cargo also performs the deployment of the webproject to the specific container(s). Thus we can really kickstart webdevelopment with a properly configured project. If this is not the case step into the tutorial configuring a webproject to simplify team development and testing first. The project is configured properly for Cargo if the pom-file contains a plugin configuration for the cargo-maven2-plugin artifact which itself contains some container configuration as shown below:

pom.xml changes

Include the following snippet in the <build><plugins> section of your project's pom.xml-file:

      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <configuration>
          <container>
            <containerId>${containerId}</containerId>
            <output>${project.build.directory}/${containerId}.log</output>
            <log>${project.build.directory}/cargo.log</log>
            <zipUrlInstaller>
              <url>${url}</url>
              <installDir>${installDir}</installDir>
            </zipUrlInstaller>
          </container>
          <properties>
            <cargo.servlet.port>${port}</cargo.servlet.port>
          </properties>
        </configuration>
      </plugin>

Further we create a new profile just for easier integration of other target platforms:

    <profile>
      <id>tomcat5x</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <containerId>tomcat5x</containerId>
        <port>8080</port>
        <url>http://www.apache.org/dist/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.zip</url>
      </properties>
    </profile>

What we finally have to do is to set the installDir property to the target directory that should contain our container installations. You can perform this by creating a settings.xml-file in the [userHome]/.m2/ directory (which is under Mac OS X only accessible through a terminal). This file can look like:

<?xml version="1.0"?>

<settings>
        <profiles>
                <profile>
                        <activation>
                                <activeByDefault>true</activeByDefault>
                        </activation>
                        <properties>
                                <installDir>/opt/cargo</installDir>
                        </properties>
                        <id>user</id>
                </profile>
        </profiles>
</settings>

Ensure that the user that is running Maven has write access to the directory your pointing with the installDir directive.

Running Cargo

To try the Cargo deployment simply use:

   mvn package cargo:start