Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Big Bad Bundle

bnd edited this page Mar 21, 2013 · 1 revision

Lets say you have a legacy Java application that consists of your own packages "com.acme.*", and some JAR files A, B and C.jar under lib/ which are required to be on the application classpath.

In Bndtools you can construct a "mega bundle" that contains all this as follows:

 Private-Package: com.acme.*
 Include-Resource: lib
 Bundle-ClassPath: ., A.jar, B.jar, C.jar

Notice 2 things. First the Include-Resource command, which is an instruction to bnd (not an OSGi header) that says to include the contents of the lib directory into the new bundle. It's worth reading the documentation of Include-Resource carefully because it's very powerful, but a little complex.

Next thing to notice is Bundle-ClassPath, this is an actual OSGi header that is the equivalent of setting the application classpath. In OSGi there is no global classpath, instead each bundle has its own internal classpath. The first entry is "." (dot) which means the bundle JAR itself should be part of the classpath, this ensures that the com.acme.* packages are visible. The remaining entries are the library JARs, which are relative to the root of the bundle... they were put there by the Include-Resource command.