Skip to main content

Bundle non-OSGi dependencies with Maven

When we work with OSGi, a problem we always have is how to work with dependencies non OSGi Ready.

This is not a really great problem because there we can work with. There is essentially two solutions :

  • Embed the JAR files within the bundle. That is to say putting the JAR file into the bundle JAR and reference it in the Manifest
  • Wrap the JAR files with an OSGi Manifest. Namely, transform the JAR into an OSGi bundle.

Personnaly, i doesn't like the first solution, because for me, having a jar into a jar sounds really weird and bad and i prefer to have real OSGi Bundle. With wrapping, if i need this library in an other bundle, i doesn't have to do anything.

But, yes there is a but, wrapping a jar is much complicated than embedding. Because, we much transform the JAR into a real OSGi Bundle. That is to say that we much create a new JAR with a Manifest, importing all the needed packages, exporting all the necessary packages, computing the names and version, ...

If we must do that by hand, that could be really long and hard to do.

We can do that in a simple way using Maven 2 and the maven-bundle-plugin that can generate an OSGi jar embedding the other using the BND tools. With some configurations, we can simply create a totally valid OSGi Bundle. To make several bundles  easily, i created a simple parent pom (i take the first sources from Spring Blog) and all the modules of this parent project will be simple project to wrap a dependency.

Here is the parent pom i use :

<?xml version="1.0" encoding="UTF-8"?>


        <!-- Modules -->




That really simple, we use some properties to generify the process to have really simple modules.

Here is an example to wrap the substance look and feel library :

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=""





Like you can see, that's really simple and that generates a great OSGi Bundle. Here i didnt' specify any export package. Doing that all the packages are exported except the ones containing impl or internal.

Thats it :)

I hope that this post will be useful to some of you.


Comments powered by Disqus