Building one big fat jar file

I've been working on software that generates a very large XML feed for customers. My plan was to have it run by a cron job and regenerate the feed once a week. I wanted my project to produce one file (including dependencies such as Spring and Hibernate) that a release engineer could drop onto the production system rather than an archive that needed to be untarred and installed. Out of stuborness I also wanted to be able to run it from cron without wrapping it with a shell script. Basically I wanted to be able to type “java -jar XmlFeed.jar” and just have it work.

I was starting to think it was going to take some significant effort to make this happen when I stumbled across Codehaus Classworlds Uberjaring. Fortunately there was a Maven Uberjar plugin so I added a maven.uberjar.main property to my project.properties file and within a couple of minutes of starting to look for a solution I had built a working jar file. Alas, I discovered the Classworlds classloader was really slow and my program ran about 15x slower than normal.

I started searching again and next stumbled across the Maven JavaApp plugin which does the same thing. I installed the plugin and within about a minute I again had one big jar, and with the Java App approach it ran at normal speed. Success!

I won't argue that Maven is the coup de gras of build systems but the fact that within a few minutes I was able to use 2 different approaches to build a big jar demonstrates the power of Maven plugins and the approach of building software by defaults. I would be just as happy if there was a repository of Ant macros that did the same thing. Until that day comes though Maven has pleasantly surprised me numerous times with plugins that have gotten me up and running quickly.

Note: I'll also add that I discussed this with a friend later and he suggested as an alternate approach that I could have also built an EAR file and run it from the command line with a J2EE app client (not within an app server).

This entry was posted in Java. Bookmark the permalink.

One Response to Building one big fat jar file

  1. Pingback: The Whiteboard » Blog Archive » Using Maven2 to build a single standalone jar file

Comments are closed.