Including JAR in OSGi Package in Eclipse

I need to embed a third-party JAR file in the OSGi package that I am developing in Eclipse. I searched and read a lot, and I repeat the same thing over and over:

  • I really shouldn't do that. This is not an OSGi “way” to do things.
  • This is actually pretty easy to do. Just insert the JAR in the root of your package and specify Bundle-ClassPath: ., jar_filename.jar in your manifest.

Good. With the exception of the JAR, I implement a tiny one and hardly use anything else that I will ever implement on this closed system, so it’s easier to insert it so that users download only one set (ease of use at the end of -ser is vital). Therefore, I am going to go against the convention and insert it.

Now, in the IDE, everything is kosher. I dumped the JAR into the src folder of my Eclipse project and configured the project build path to enable it using the "add jar" button (and not the "add external jar", as I am convinced that it will use the absolute path) of the "configure build path" dialog " I also added the Bundle-ClassPath to the manifest file. In the IDE, all my import solutions are fixed in the exact order (because they are in the build path), but when I export it as a package (default settings), the error log shows that the import cannot be resolved.

I checked the finished JAR file of the package 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 this library, it fails.

The following is my (very simple) MANIFEST.MF . Am I missing something? Do I need to list it as an import package in addition to listing it in the bundle-classpath? Do I need to export it (why?)? Am I using pathle-classpath incorrectly? Do I need to do something differently because I use 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 all of this using the GUI, rather than directly editing the .MF file. I think Eclipse sets up some background configuration when you do this.

+6
source share
2 answers

Instead of putting the .JAR in the src folder of the project and directly editing the manifest file, refer to it as if it were at the root (although it really was at the root of the package, apparently this did not work), I was able to solve this problem using the Eclipse graphic manifest editor.

  • Put the external JAR at the root of the Eclispe project.
  • Open the META-INF / MANIFEST.MF file in Eclipse.
  • On the "Runtime" tab, select "Add ..." and add an external JAR.
+4
source

You need the entry "Export-Package" to indicate which packages are available for other plugins.

You can specify this in the Eclipse MANIFEST.MF editor on the Runtime, Exported Packages tab.

0
source

Source: https://habr.com/ru/post/978036/


All Articles