Building a Megajar with Maven2 - The Right Way

A megajar or uberjar is one jar file where all the contents of all dependent jars have been unpacked, and then everything has been re-jared up together again.

This is normally a very Bad Thing.

However, there are occasional one-off uses for such a thing. I’ve made a habit of following the advice given by the Pragmatic Programmers (here and here) by always creating a tools or util directory off the trunk of my project. I find that there are occasionally little things I do from the command-line to mass-update the source (for a package refactoring, perhaps), or there are small tools needed for one-time data conversions when a release is rolled out. I put those things in version control instead of losing them. I like to put the JIRA issue key in their name (e.g. PRJ-12-migrate-start-times), since this emphasizes the problem the tool is solving as well as its use only for the nonce.

For one such tool we did lately, we needed only one dependency — the database driver jar file. Since we don’t run these things in production, it was important to make this thing as simple to use as possible. Hence, we decided that bundling the driver for this one-off tool was simpler than a lengthy set of instructions for the Release Team.

The command I used was

mvn assembly:assembly -DdescriptorId=jar-with-dependencies

You can find more information around the web. I found the Maven2 Assembly Plugin docs fairly helpful. I also added this snippet to my pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>my.package.to.my.MainClass</mainClass>
      </manifest>
    </archive>
  </configuration>
</plugin>

So that the entire thing can be run with a simple Java command:

java -jar target/PRJ-12-migrate-start-times-1.0.0-jar-with-dependencies.jar

Got any tips for using the tools directory in your project?

Moving from WordPress 2 over to Typo 4

I’m in the middle of moving my blog from WordPress 2 to Typo 4. I’ve got the articles imported, and the migration script took care of that part. It also grabbed the categories I had and turned them into tags — too bad I wasn’t using WP categories; I was using Jerome’s Keywords. So now I’ve gotta go in and pull the keywords out of the metadata and connect them with my Typo posts. I also need to pull in the comments (for some reason they didn’t come in with the migration script). I probably messed something up there.

I did modify the routes.rb file to mimic the permalink structure I had with WordPress. It was important to keep my existing links workable (especially feed references), even if the new ones use a different format.

It also didn’t seem to pull in my podcast episodes. I’ve got a few simmering on the back burner right now, but I guess I need to figure out how to make the feed again before I put together another one.

I do like the personalization options this screen has, though the default font titles don’t handle non-Roman characters like this one. It’s not a big deal, though, since you can switch the font choice in the “personalization” section of the header to see the proper title.

So overall, it hasn’t been as smooth as I would have hoped, but it isn’t the end of the world either. I’m pretty happy, and I’m running Apache 2 + Mongrel now. That’s gotta be more fun. :-)

The $100 Contest for Ruby Blogging

If I hadn’t been so swamped this past week I may have noticed the $100 Contest for Ruby Blogging. I looks like they have some great entries so far. Too bad I’m a bit late to enter myself.