jump to navigation

Creating JAR files with dependencies February 16, 2009

Posted by Phill in Other Stuff.
Tags: , ,
trackback

File this one under “spend a few minutes Googling without success!”

If you’re trying to package up a Java application into one JAR file for easy deployment – including all dependency JAR files – there aren’t many options.

There’s a plugin for Eclipse called “Fat Jar” which I haven’t tried out. I’ve just discovered a tool called One-Jar, which does the trick. It’s simple to use. In my case, using Ant, it was a matter of:

  • Download the One-Jar JAR file.
  • Run it (using java -jar) to extract the contents
  • Add the one jar ant task plugin .jar file to my ant lib folder
  • Import the one-jar-ant-task.xml build file into my build file
  • Create a manifest.mf file with the One-Jar-Main-Class set
  • Add in the <one-jar> task to my existing build.xml file as per the instructions.
  • And you’re done!

The ant task does a lot of the work for you so it’s nice and easy. I’d recommend it, if you’re looking for a quick way to include dependencies in a single JAR.

Advertisements
%d bloggers like this: