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.

XOM and Jaxen Transitive Dependencies with Maven

I briefly looked at using XOM to do some XML parsing in a Maven 2-built Java project this afternoon, only to discover that XOM has a transitive dependency on Jaxen and Jaxen has a transitive dependency on all of DOM4J, JDOM, Xercse and XOM again.


This is frustrating.  Seems to come from the fact that the Jaxen team didn't build Jaxen's POM (JAXEN-138, JAXEN-151, MEV-413), and nobody else wants to take responsibility for it.  

The longer-term fix is the thought (July, 2006) that Jaxen might move to Maven 2.  I'm quite tempted to volunteer for that port simply to solve this problem for me in the future.

Wednesday, October 29, 2008

Mortal Life as Sorting Algorithm

I was thinking last night about some amalgam of traditional religion, while waiting for my wife to emerge from an event being held in a church. Pierrette to come out of a La Leche League meeting in a Unitarian church.

Imagine that in a vaguely Catholic-like way, mortal life is simply a classification system for people (or souls). A giant sorting machine at the beginning, very brief in the grand scheme of your existence. And that, basically, when you're done being sorted along with your fellow mortals, you spend the rest of your existence in the company of your equals, in tiers.

So the reward for being good on earth is spending your time with other people who were good, and the punishment for being a d*ck is spending eternity with other d*cks. The golden rule isn't so much an exhortation as a tip for finding the right tier in your afterlife: "Do unto others as you want others to do unto you for the rest of your very, very long post-life existence."

After beta trials, God notices that some people attempt to game the system. Like any good game designer, Allah realizes that he needs some special tiers for those people who are gaming the system. In the same way that a video game might have an invincible mode that is completely out-of-proportion difficult for those who've already finished the 'hard' level with all their ammo and never having been hit, The Earth Mother realizes that those maximizing for altruism beyond all expectation deserve a special tier to be called Heaven, and that those who maximize for self-interest at any cost should have a special tier called Hell, where the reward and the punishment is also more than simply being sorted with your peers.

Unfortunately, the publicist screws up and the media take the sensationalist points and only covers Heaven and Hell, leaving out the important salient points about how most people will get sorted.

Tuesday, October 28, 2008

Demand for iPhone Developers up Infinite Percent

Since the iPhone was introduced, demand for iPhone developers has skyrocketed to infinity when compared to the previous non-existent demand.  Now that the iPhone has been released, it seems that some people occasionally want to hire people to develop for it.  Truly stunning news from the Apple Blog.


Is this really news?  Of course demand for development in a totally new technology is showing significant growth.  That's true of any technology that's seeing any real new adoption, and it's certainly true that the iPhone falls into that category.

Wednesday, October 22, 2008

Living in the Shadow of a Non-Factor

From Managing Humans, by Rands:

The organization's view of your manager is their view of you.  I'm glad you're a C++ rock star, but the problem is, your manager is passive non-communicator who doesn't take the time to grok the political intruigue that's created by any large group of people.  I see him as a non-factor and you're living in the shadow of a non-factor.
I've seen that very thing happen. 

Tuesday, October 21, 2008

Katamari Damacy Garbage Art

Look, Katamari Damacy visits the dump to create as Art.

Monday, October 20, 2008

Experimenting with jQuery

I've done a little experimentation with jQuery while building out geoffreywiseman.ca.  I've been meaning to get a little deeper into AJAX and jQuery was one of the libraries that appealed to me.  It went pretty well for the most part, although I'm not yet sure if it took me less time to learn jQuery than it would have taken me to do the work by hand with JavaScript.  Seems pretty powerful as a library, though.


I did some experimentation with jQuery animations, but quickly discovered that it wasn't going to do the job for me -- you can roll over the icons faster than the animations typically run, and it's very difficult to get a set of animations happening in sequence, cancelling each other without tripping over your own feet, so I dropped the animations.

Even then, I was pleased to realize that I could accomplish this all in presumably cross-browser code without having to test in all these browsers.  Out of curiosity, I fired up IE7 this morning, only to discover that although the site works well in Chrome and Firefox, it's got problems in IE7. 

Ah, browsers.   Can't code web-apps without 'em, can't kill the vendors who wrote such incompatible clients without getting arrested.  This is one of the things that had me focus on server-side code for most of my career.  I'm hoping there's an easy fix.

Saturday, October 18, 2008

Movin' On ...

Well, the writing's on the wall for my current employment.  While I'm not moving on right away, it's time to start keeping an eye out for anything interesting.  In many ways, that's just more of the same, since I do that for Toronto Technology Jobs.


In the meantime, I decided this was a good opportunity to resurrect a personal site, so I've been getting the basics together up at geoffreywiseman.ca.

If you're looking, or know someone who is in the Toronto area, drop me a line, either because you're interested in having me take a look for TTJ or because you think I might be a fit.

Tuesday, October 14, 2008

Eclipse Update Problems: No Repository

So recently when trying to update just about anything in Eclipse, I've been getting errors complaining about "no repository found for..."  I ignored this a few times assuming it was some kind of weird transient error, but it hasn't gone away, so I did a little more digging.


Turns out this is a relatively common occurrence in recent versions of Eclipse, there's a bug they're having trouble reproducing, and the simple workaround at this point is to remove and re-add update sites that are giving you problems.

Worked for me; hopefully raising awareness will help some of you.