I need to embed a third-party JAR file in the OSGi bundle that I'm developing in Eclipse. I've done a lot of searching and reading, and I keep seeing the same things over and over again:
- I really shouldn't be doing this. It isn't the OSGi "way" of doing things.
- It's actually pretty easy to do. Just embed the JAR at the root of your bundle and specify
Bundle-ClassPath: ., jar_filename.jar
in your manifest.
Okay. Except the JAR I'm embedding is tiny and unlikely to be used by anything else I will ever implement on this closed system, so it's a lot easier to embed it so that users only have to download one bundle (ease of use for the end-user is vital). So I'm going to go against convention and embed it.
Now, in the IDE, everything is kosher. I dropped the JAR in the src
folder of my Eclipse project and configured the project's build path to include it using the "add jar" button (not the "add external jar", since I'm lead to believe that will use absolute path) of the "configure build path" dialogue. I also added the Bundle-ClassPath
line to my manifest file. In the IDE, all my imports resolve fine (because it's in the build path), but when I export it as a bundle (default options), the error log shows that the imports could not be resolved.
I checked the final bundle JAR file that was generated, and the third-party JAR is nested inside (at the root) as expected, but as soon as it tries to import objects from that library, it fails.
Included below is my (very basic) MANIFEST.MF
. Am I missing something? Do I need to list it as an import-package in addition to listing it on the bundle-classpath? Do I need to export it (why?)? Am I mis-using bundle-classpath? Do I need to do something differently because I'm using Eclipse?
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ZWave Demo
Bundle-SymbolicName: com.wbarlow.zwavedemo
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.wbarlow.zwavedemo.internal.Activator
Bundle-Vendor: WBARLOW
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-ClassPath: .,
rxtx-2.1.7.jar
EDIT: I solved this by re-doing it all using the GUI rather than editing the .MF file directly. I guess Eclipse sets some background configuration when you do that.