While many open source libraries already natively support OSGi, there are still some that do not have the required metadata added by default. Fortunately, there are a number of strategies that can be used to enable the libraries to be used in OSGi runtimes such as Eclipse, or repositories such as Eclipse Orbit (http://eclipse.org/orbit/) that contain corrected bundles.
If the library is only needed in one bundle, then the most expedient mechanism is to embed the JAR(s) into that bundle. Since all libraries in a bundle share the same classpath, this allows the library to run without being aware of the fact that it is running in an OSGi environment. This can be done by embedding the JAR into the bundle and using a Bundle-ClassPath
header that refers to the library:
Bundle-ClassPath: .,lib/example.jar
Note that the dot (.
) must be present if the bundle itself contains classes, or to enable other resources to be loaded. This approach works well...