Created
October 17, 2011 02:59
-
-
Save rotty3000/1291842 to your computer and use it in GitHub Desktop.
Creating a fragment bundle that adds exposes more classes from the outer env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://blog.meschberger.ch/2008/10/osgi-bundles-require-classes-from.html | |
How can an OSGi Framework be extended ? | |
A framework can be extended in two ways: Either by extending the list of packages available in the framework itself by ammending the System Bundle export list or by adding classes to the framework boot class loader. | |
To extend the framework the bundle must have the Fragment-Host manifest header set to either the actual bundle symbolic name of the system bundle as defined by the framework vendor. Alternatively the alias of the system bundle name, which is system.bundle may be used. I prefer the latter case because it would not create vendor lock-in on the Extension Bundle. | |
The type of extension is indicated by the extension directive of the Fragment-Host manifest header. The directive may take either of the following values: | |
framework -- A framework extension ammends the System Bundle export list | |
bootclasspath -- The Extension Bundle jar file is added to the class path of the class loader loading the OSGi framework. As such, the classes from the Extension Bundle jar file are actually loaded outside of the OSGi framework. | |
Example 1: Provide the com.sun.image.codec.jpeg Package | |
To continue our initial example, lets see how the com.sun.image.codec.jpeg package can actually be made visible to our Captcha bundle. To do this, we just need a manifest file which we package into a standard JAR file using the jar tool. | |
First create a file -- say manifest.mf with the following contents: | |
Bundle-ManifestVersion: 2 | |
Bundle-SymbolicName: ch.meschberger.sample.extension | |
Bundle-Version: 0.0.1 | |
Fragment-Host: system.bundle; extension:=framework | |
Bundle-Name: Sample Framework Extension | |
Bundle-Description: Sample Bundle exporting Sun's JPEG classes | |
Export-Package: com.sun.image.code.jpeg | |
Now, create the bundle JAR file: | |
$ jar -cfm ch.meschberger.sample.extension-0.0.1.jar manifest.mf | |
That's it. After installing this bundle in your framework you can use the Sun JPEG classes as usual. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment