Wednesday, July 15, 2009

When the PDE(JDT) met the Jar-in-Jar bundle

When the PDE(JDT) met the Jar-in-Jar bundle

"Jar-in-Jar" is a word using in the 3.5M5 new and noteworthy page. A Jar-in-Jar bundle is just the jarred bundle which contains other jars. (sometimes, called "nested Jar".)

Recently, when I use the db4o osgi bundle, I met a compilation problem. It said,
"the type com.db4o.ObjectContainer cannot be resolved. It is indirectly referenced from required .class files".

From one entry in its forum, I know that, it is an old problem after the db4o get into the world of osgi.

After a simple inspection, I find the reason. That is, the PDE can not resolve the Jar-in-Jar bundle. The old Bug157375(and Bug 111238 as well) addressed this problem. As Jeff suggested in the comments, the best practice for this is "packaging each JAR as a bundle and not nesting JARs at all".
However, as Jeff said as well, "Equionx(and other OSGi implementation?) will run JAR'd bundles with nested bundles just fine". So, this just causes a compilation error, but not a runtime problem. I think this bug is still a bug.

As Thomas Watson said, this bug "well actually is JDT" bug. Jeff simply suggested a bug-fixing idea: "basically if the bundle has JARs on the classpath then unzip in a temp spot and us the temp location for classpath computations". But the Bug 111238 seemly said more problems with extraction method. I have one idea, like using some detecting codes just to check the correct dependency of the jar-in-jar on the fly and to avoid the compilation blocking. In the other aspects, we can still use the original bundle.

Lastly, two workaround for this bug: 1. using the best practice pointed by Jeff; 2. unzipping the jar, then using the directory-style bundle.

Warning: If you are the man responsible for building your osgi bundle, please keep the best practice. "nested jars are evil"(zx^_^).

No comments: