1

I know there are two ways of using external libraries in OSGI bundles. As only my package needs the lib (e.g. google-gson) I tried to put it in the Bundle-ClassPath (manifest.mf). But whenever I run the bundle in Knopflerfish I get the Exception in thread "Thread-74" [stderr] java.lang.NoClassDefFoundError: com/google/gson/Gson.

As I am new to OSGI I tried to follow the instructions for creating a bundle from here using a build.xml for compilation where I also included the lib (don't know if this is even correct). So the library appears in three different places, the project classpath, the bundle classpath (manifest.mf) and the build.xml.

I would be glad if someone could give me a hint how to make the library work. Thanks in advance!

nyyrikki
  • 1,436
  • 1
  • 21
  • 32
  • In the end I choose the second approach and created an OSGI bundle from google-gson. So I do not need to care about including the library into my bundle. Everything else was not working :( – nyyrikki Feb 26 '13 at 13:43

2 Answers2

1

The process as follows

1.copy all the .jar files and its DEPENDENCIES to a folder

2.mention it in BUNDLE-CLASSPATH in MANIFEST.MF .Refer this

3.Importantly add packages from this library to Export-package element in MANIFEST.MF to make it visible for other bundles.

Hope this resolves your issue

Community
  • 1
  • 1
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
0

Few hints that may help and work for me:

  • The MANIFEST.MF of the bundle may have a line like Import-Package: org.osgi.framework. In that line you should add the import of the desired package from the library, so it remains Import-Package: org.osgi.framework, com.google.gson
  • As TheWhiteRabbit said in its answer, libraries should have an export line like Export-Package: its.sec.api.service, so other bundles may see it. Libraries that are already compiled and packaged usually are already setup, but I found some that hasn't so is a good practice to check it.

Also remember that external libraries may be installed into the framework as if it were bundles, i.e. in the init.xargs - install jars/myLib/myLibrary.jar Installed but not started.

Hope this helps

CarlosRos
  • 389
  • 6
  • 15