Tuesday 20 October 2009

One JAR for all your JARs

Sometimes it is more convenient to package your Java application into a single JAR which includes all dependencies and works just like an executable. This seemingly simple objective becomes complicated when the dependencies include other JAR files as one can run into JAR Hell with the Java Class Loader. One possibility of achieving the goal of having a single executable jar is using One Jar.
The unique aspect of OneJar is that dependencies can be bundled into the executable Jar in their native form without unpacking the classes and the custom class loader resolves and loads required classes from within the dependent jars. The default Java class loader can only load classes from the file system, it cannot look inside other jars for the required classes. To achieve loading of classes from within other jars, a custom class loader is required which is provided by One Jar.One Jar also provides an Ant and a Maven2 task and can be easily integrated into your build cycle.

No comments: