Showing posts with label cargo. Show all posts
Showing posts with label cargo. Show all posts

Friday, October 31, 2008

Configuring Cargo/Tomcat with Maven2

Commenting on my last post, Rob Sinner asked, "Can you post the pom.XML your using to launch cargo[?]"  I haven't had the problem he described, but I don't mind sharing the configuration I use.


Basic Cargo/Tomcat Configuration
A basic cargo/tomcat configuration adds the cargo plugin to your build plugins. If you place this within a WAR module, the module in which the cargo plugin is defined will be automatically deployed with no extra work on your part:

<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<container>
<containerId>tomcat5x</containerId>
<zipUrlInstaller>
<url>http://www.apache.org/dist/tomcat/tomcat-5/v5.5.27/bin/apache-tomcat-5.5.27.zip</url>
</zipUrlInstaller>
</container>
<configuration>
<home>${project.build.directory}/tomcat5x/</home>
<properties>
<cargo.servlet.port>${servlet.port}</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
To fire up cargo, simply enter:
mvn cargo:start
To exit, press Ctrl-C.

Integration Tests
You can configure Cargo to start before the integration test phase and shut down after the integration test phase. This is useful if you have automated integration tests that you'd like to run against your in-container application. It's as simple as binding the cargo goals to the correct lifecycle phases:

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

Deploying Other Modules
In some cases, you'll want to deploy one or more modules that aren't the project you're in. In this case, you'll want to define deployables explicitly inside the cargo configuration:

<deployables>
<deployable>
<groupId>com.mycompany.myproject</groupId>
<artifactId>myproject-alpha</artifactId>
<type>war</type>
<properties>
<context>alpha</context>
</properties>
</deployable>
<deployable>
<groupId>com.mycompany.myproject</groupId>
<artifactId>myproject-beta</artifactId>
<type>war</type>
<properties>
<context>beta</context>
</properties>
</deployable>
</deployables>
Debugging
If you want the option of connecting a remote debugger to tomcat after firing it up via Maven/Cargo, I'd suggest a profile.  This is what we typically use:

<profile>
<id>cargo-debug</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0-alpha-6</version>
<configuration>
<configuration>
<properties>
<cargo.jvmargs><![CDATA[-Xdebug -Xrunjdwp:transport=dt_socket,address=15102,server=y,suspend=n]]></cargo.jvmargs>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>

You can invoke this using:
mvn cargo:start -Pcargo-debug

Alternatives
There's also a Maven Jetty Plugin which has a pretty good reputation.  Unfortunately, there are currently two plugins with the jetty prefix, one in the mojo repository, and the other from mortbay.  The former takes precedence for me, whicih makes using the Mortbay version painful.

Thursday, October 30, 2008

Maven 2 Cargo Plugin: Version-Hell

I'm working on a small architectural spike, and I want the ability to run my WAR project in a container.  In past projects, I've configured Cargo's Maven 2 plugin to launch Tomcat, both for manual testing and for integration tests.  While I don't really need integration tests on this spike, I prefer to have the build-integrated option to launch a container rather than deploying the WAR to a container manually.


Maven 2 is Configuration-Over-Convention: configuring Cargo for a Maven 2 build takes a page of XML.  Rather than compose it from scratch, I just grab it from past projects.  After doing so, I refine it for any project specifics, and while I was in the fancy m2eclipse dependency editor, I did a quick check to see if 1.0-alpha-6 was still the current version.  Seem's not -- the dialog shows me that there's a 1.0-beta-1 version available.

I prefer to use the most recent version unless there are significant changes, so I thought I'd best check to see what's changed, only to discover that getting that information is nigh-impossible:
  • The home page lists the 'current version' of the Maven2 Plugin as "0.3", despite the fact that that version is a year old, and there's been a series of alphas and now betas since then.
  • The 'news' section is even older, showing that 'Version 0.2' of the cargo-maven2-plugin has been released, same as the announcements mailing list.
  • Although Cargo seems to use different version numbers for its various components, their Jira is configured with a Cargo project and the Maven2 plugin as a component.  In order to address the overlapping version space, they've created versions like 1.0-maven2.
If anyone knows what changed from alpha-6 to beta-1, please feel free to comment.  I give up.