Skip to main content
Jump to: navigation, search

Difference between revisions of "Creating OSGi Bundles from Third-Party JARs"

(Created page with "== OSGi Bundles vs. Stand-Alone JAR libraries == An OSGi Bundle is simply a [http://en.wikipedia.org/wiki/JAR_(file_format) JAR], with the added metadata contained in the MAN...")
 
(Changed references to NiCE to ICE and added inline reference.)
 
Line 1: Line 1:
 +
 
== OSGi Bundles vs. Stand-Alone JAR libraries ==
 
== OSGi Bundles vs. Stand-Alone JAR libraries ==
  
 
An OSGi Bundle is simply a [http://en.wikipedia.org/wiki/JAR_(file_format) 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 OSGi Bundle is simply a [http://en.wikipedia.org/wiki/JAR_(file_format) 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 NiCE to JMonkey ==
+
== An Example: Connecting ICE to JMonkey ==
  
NiCE has run into this 3rd party JAR problem in its Geometry Editor and analysis tools. The NiCE 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 NiCE's OSGi framework. There are a number of ways one can create an OSGi Bundle from existing 3rd party JARS, (1):
+
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:<ref>J. McAffer et. al., ''OSGi and Equinox: Creating Highly Modular Java Systems''</ref>
  
* Bundling by Metadata Injection
+
*Bundling by Metadata Injection
* Bundling by Wrapping
+
*Bundling by Wrapping
* Bundling by Reference
+
*Bundling by Reference
  
NiCE 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.
+
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'' &gt; ''New'' &gt; ''Project...'' &gt; Plug-in from existing JARs.
+
*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
+
*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
+
*Click Finish
* Go to the new project and open its MANIFEST.MF file.
+
*Go to the new project and open its MANIFEST.MF file.
* Under the ''Runtime tab'', &quot;Add&quot; all packages to its ''Exported Packages'' section to allow other applications to use the provided classes
+
*Under the ''Runtime'' tab, "Add" all packages to its ''Exported Packages'' section to allow other applications to use the provided classes
* Save and close
+
*Save and close
  
 
The resultant project is exactly like any other bundle project and can be exported and added to a target platform.
 
The resultant project is exactly like any other bundle project and can be exported and added to a target platform.
  
 
== References ==
 
== References ==
 
+
{{Reflist}}
# J. McAffer et. al., ''OSGi and Equinox: Creating Highly Modular Java Systems''
+

Latest revision as of 08:19, 9 July 2015

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