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:
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.
Rather than putting the .JAR in the project's src folder and directly editing the manifest file to refer to it as if it is in the root (even though it really was in the root of the bundle, apparently this didn't work), I was able to solve this problem by using Eclipse's graphical manifest editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With