Search code examples
javamavendependenciesosgiosgi-bundle

OSGI and maven dependencies among bundles and jars


I got a question regarding OSGI Bundles and "normal" maven jar dependencies.

The following scenario:

A multi module maven project: A

with the modules A.X, A.M:

A.X is a OSGI Bundle

A.M is normal java application that launches the OSGI framework and loads the bundle A.X

In the project top-level pom (A.pom) I define a dependency to commons-logging-1.1.1 Then I use commons-logging in my OSGI Bundle A.X. The maven-bundle-plugin generates the manifest for A.X with an import entry where 'commons-logging' occurs.

When I start A.M and print out all my loaded jars (with getSystemClassLoader...) on the console then ../../../commons-logging-1.1.1.jar is listed. Because of the maven-dependency from the top-level pom.

Now I try to install my OSGI bundle A.X and get a "unresolved constraint in bundle.....commons-logging" exception.

Why can´t the commons-logging dependency (from A.X) be resolved with the commons-logging lib that is already in memory (in A.M) when the bundle is installed?

I am grateful for any help!!!!


Solution

  • Printing out the loaded jars with getSystemClassLoader doesn't necessarily tell you what's available via OSGi - remember that OSGi has it's own class-loading mechanisms.

    As I understand, the commons-logging must be exported from some other bundle so that OSGi can wire it up to your A.X component - likely there is bundle or feature for commons-logging that you can easily add as a dependency.

    I'm not sure which OSGi container you're using (I use Fuse), but there should be some way to look at the imports and exports of the bundles you are using. Since A.X imports commons-logging, another bundle needs to export it (with appropriate version).

    In the fuse world, adding a dependency to a system bundle is as easy as adding it to a features.xml file. But since I don't know which container you're using, I'm not sure how you can do this.

    Does this help?