OSGi and native events

371 views Asked by At

I am using a lib which communicates with another application through some native connection.

I have no sourcecode whatsoever of this lib, so i cant really specify how the application actually communicates.

Anyway, it works pretty well and i can communicate to the application. With this lib i can listen for events that happen in the other application. I can register for events and a listener is called with a special event-class.

Using OSGi, this event-class fails to load with the java.lang.NoClassDefFoundError exception. Every Event is triggered in its own new thread. The package is imported correctly, and i can use the class throughout my code.

The Library i use is the HACL library by IBM.

Is this a problem of the API? or is it because of how native Events are handled? Can i somehow make the OSGi Classloader known to those new Threads?

Thanks.

The full stack trace is:

Exception in thread "Thread-20" java.lang.NoClassDefFoundError: com/ibm/eNetwork/ECL/event/ECLPSEvent
Caused by: java.lang.ClassNotFoundException: com.ibm.eNetwork.ECL.event.ECLPSEvent
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
2

There are 2 answers

0
Arie van Wijngaarden On

First of all: I don't know the IBM product you are using, but only making suggestions from other external libraries I used in OSGi.

The suggested way to go is to include all the jars that are needed for the external library to work into your own bundle (common solution is to put them in a separate folder) and extend your bundle classpath to adapt this situation. Note that you need to specify all the jars here. Example:

You product consists of "a.jar" and "b.jar" and you copied them to the lib/ directory in your bundle, then the bundle class path must be:

Bundle-ClassPath: .,lib/a.jar,lib/b.jar

assuming that your own code goes to the root of the bundle jar.

Common mistakes:

  1. Forgetting to include the dependencies jars in the bundle classpath as well.
  2. Forgetting to include the jars in the bundle during the build/export.
  3. Forgetting to import the packages that are needed by the product jars.

All these will result in some kind of ClassNotFoundException. My impression is that in your situation, the problem may be due to 1.

0
Wolfgang Fahl On

You'll need to have pcseclj.jar in your class path. It ships e.g. with IBM Personal Communications 6.0 which you can e.g. download from https://www.ibm.com/developerworks/downloads/r/pcomm/

You'll find the jar file in

/mtri1006/combo/Disk1/program files/IBM/Personal Communications

after unzipping the Trial download.