Simplify Your Application Delivery with One-JAR
By P. Simon Tuffs2005-04-22
In Conclusion
If all this has left your head spinning, don't worry: Using One-JAR is much simpler than trying to understand how it works. With the advent of the FatJar Eclipse Plugin (see FJEP in Resources), Eclipse users can now create a One-JAR application by selecting a checkbox in a Wizard. The dependent libraries are placed into a lib/ directory, the main program and classes are placed into main/main.jar, and the META-INF/MANIFEST.MF file is written automatically. If you use JarPlug (again, see Resources) you can look inside the JAR file you built and launch it from within the IDE.
Overall, One-JAR is a simple yet powerful solution to the problem of packaging applications for delivery. It doesn't provide for every possible application scenario, however. For example, if your application uses an older-style JDK 1.1 classloader that doesn't delegate to its parent, then the classloader will fail to locate classes from within a nested JAR file. You could overcome this by building and deploying a "wrapping" classloader to modify the recalcitrant classloader, although this would entail using bytecode-manipulation techniques with tools such as Javassist or Byte Code Engineering Library (BCEL).
You might also encounter problems with some particular types of classloader used by embedded application and Web servers. Specifically, you could have problems with classloaders that don't first delegate to a parent classloader, or those that look for codebases in the filesystem. It should help that One-JAR includes a mechanism by which it can expand JAR file entries into the filesystem. The mechanism is controlled by a One-JAR-Expand attribute in the META-INF/MANIFEST.MF file. Alternatively, you could try using bytecode manipulation to modify the classloaders on the fly, without violating the integrity of the supporting JAR files. If you go this route, each individual situation will probably require a customized wrapping classloader.
See Resources to download the FatJar Eclipse Plugin and JarPlug, and to learn more about One-JAR.
Tutorial Pages:
» Power Programming with Custom Classloaders
» Overview of One-JAR
» Problems and solutions
» Enter the JarClassLoader
» Loading Resources
» Bootstrapping the JarClassLoader
» In Conclusion
» Resources
First published by IBM DeveloperWorks
