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:


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?

comments powered by Disqus