Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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:[1]

  • 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.

References

  1. J. McAffer et. al., OSGi and Equinox: Creating Highly Modular Java Systems

Back to the top