Creating OSGi Bundles from Third-Party JARs
OSGi Bundles vs. Stand-Alone JAR libraries
An OSGi Bundle is simply a JAR, with the added metadata contained in the MANIFEST.MF file. Thus, any OSGi bundle will behave exactly as a JAR in an environment that does not depend on OSGi mechanisms. So it seems logical that developers would provide their JARs with the added metadata to allow their software to be used as both a stand-alone library as well as an OSGi plug-in. Unfortunately, this is not yet the norm, so it becomes necessary to learn how to transform 3rd party JARs into an OSGi equivalent bundle.
An Example: Connecting ICE to JMonkey
ICE has run into this 3rd party JAR problem in its Geometry Editor and analysis tools. The ICE Development team has decided to use the scene graph and geometry manipulation functionality provided by JMonkeyEngine. However, it is shipped as a collection of stand-alone JAR archives and has no mechanisms to connect it to ICE's OSGi framework. There are a number of ways one can create an OSGi Bundle from existing 3rd party JARS:
- Bundling by Metadata Injection
- Bundling by Wrapping
- Bundling by Reference
ICE has converted the JMonkey JARs into an equivalent OSGi Bundle using the Injection method. The following is a short tutorial on how to create an OSGi bundle from a collection of regular JAR archives using metadata injection.
- Open Eclipse and create a new bundle project using File > New > Project... > Plug-in from existing JARs.
- Make sure the Unzip the JAR archives into the project box is checked so that the wizard will unpack all the JARS as they are imported into the new project
- Click Finish
- Go to the new project and open its MANIFEST.MF file.
- Under the Runtime tab, "Add" all packages to its Exported Packages section to allow other applications to use the provided classes
- Save and close
The resultant project is exactly like any other bundle project and can be exported and added to a target platform.
- ↑ J. McAffer et. al., OSGi and Equinox: Creating Highly Modular Java Systems