JARs in JARs

I just voted for Bug 4648386: “Simplify deployment and versioning by embedding JAR files within each other”. This bug has been open since 2002 and has 145 votes.

One workaround is to unzip all of your JARs and then re-bundle into a single JAR. While this is easy enough, I would recommend using Jar Jar Links whenever you re-package classes into custom JARs.

A few years back, we had a case where a 3rd party library had embedded JDOM beta 8 into their JAR, but they did not change the package names. When we tried updating our applications to JDOM 1.0, we ran into conflicts because the old JDOM was embedded into one of the JAR files we needed. This is exactly the kind of problem that Jar Jar Links can eliminate.


I think I’m vote #148.

For a bug to be open this long, there must be something “funny” about repackaging Jars; are there any services/things that depend upon having signed dependencies?

Josef Says:

I’m sure this feature will be supported. WARs and EARs already do. OSGi has supported this for years now, and Sun is revisiting this in their own “duplicate” efforts.

Alex Miller Says:

JSR 277 defines a new Java modularity archive (a JAM) and if I recall, it includes support for jars in a JAM.

I’ve run into problems with re-jarring in the past with signed or sealed jars. One useful thing I have used is the Ant jar task support, which includes the ability to pretty easily merge jars. I think it does it more efficiently than than just exploding and re-jarring by updating directly into the target.

Dan Lewis Says:

added my 3 votes

I’ve had good experience with One-Jar: http://one-jar.sourceforge.net/
and especially with its nice integration with FatJar http://fjep.sourceforge.net/