tags:

views:

48

answers:

4

I am developing OSGi bundles using Eclipse. I test the code, using an Eclipse OSGi runtime configuration.

The code works fine there, but when I export the bundles as jars and try to use them in another environment (pax-runner, for instance) I get ClassNotFound exceptions at runtime. The bundles are installed fine, with no errors. I execute the command on equinox: "diag bundle-number" and it says: "No unresolved constraints" for every bundle.

I would like to know if there is a tool/method to know, for a given .jar bundle if it needs any external library, which is not described in the manifest.mf.

A: 

I've done something like this a while back (I was cross compiling Java to .NET via IKVM, but needed the dependencies between Jars) I used JarAnalyzer to create a graph of dependencies.

mlk
+1  A: 

JBoss has just release a fantastic Open Source diagnostic tool about dependencies : http://jboss.org/tattletale

One of the features is to analyse the jar files by introspection, to find all lacking dependencies.

Benoit Courtine
+1  A: 

Your bundle will resolve if all the packages listed in Import-Package (and the bundles listed in Require-Bundle) are found at runtime. If you get ClassNotFoundException or NoClassDefFoundError after resolving, it means that the content of Import-Package was wrong.

Take a look at the Bnd tool by Peter Kriens. This performs static inspection of the bytecode compiled from your classes to discover the exact dependencies, and it generates the Import-Package statement for you. In general if you use Bnd, you should never see ClassNotFound/NoClassDefFound unless dynamically load classes by name, e.g. with Class.forName().

Neil Bartlett
A: 

I've had success with SpringSource's bundlor-shell tool. There are instructions for using it here. You give it a JAR, along with a name and version for the new bundle you want to create from that JAR. It then analyses the class files inside the JAR and produces a template manifest that imports any packages it finds references to.

The hard part is then working out which dependencies are optional, and what version of each package to depend on. You have to read the web site, release notes, etc. for the library to figure this out.

You will get "No unresolved constraints" if the bundle doesn't actually import any packages or require other bundles; as far as the OSGi runtime is concerned, the bundle will be usable. But as soon as it accesses an external class, as in your case, you'll get the dreaded ClassNotFoundException.

Richard Fearn