I have replicated your setup and I am getting the same exception.
The problem can be solved with:
- add native library to plugin-1
- add the Bundle-NativeCode directive to the plugin-1 manifest
- load the library into the static constructor of the plug-in activator-1 (you can write one and add it to the plug-in)
Some other possible sources of errors: Keep in mind that the package path, class name and method signatures should never be changed for any class with its own bindings. Otherwise, JNI will not be able to find the native copy, and you will get UnsatisfiedLinkError. In the import directive, you specified the following class name com.external_library.MyLibraryClass, but your error message has a different class name com.external_library.MyLibrary_javaJNI. Check out these sources of errors.
Additional explanations: The JUnit test, unlike the JUnit plug-in test, does not start the OSGi environment. Therefore, you have a simple Java application with the usual JUnit test. If your native lib and your application are contained in the same folder (top level), the native lib will be automatically found in the windows. If this is true for UNIX systems, this will explain why your JUnit test is successful. If it is in a different folder, you must specify the Java library path for a regular Java application.
EDIT MrMas: Modify plugin-2 so that it does not depend on plugin-1 by adding the .jar file to plugin-2.
- Copy the .jar file to plugin-2. I put it in the same directory as .so.
- Add the jar to the project through: Project-> Properties-> Libraries-> Add Jar
- Add jar to class path through plugin.xml-> Runtime-> ClassPath section-> Add
- Export packages from Jar (if needed for downstream plugins)
- Remove the plugin-1 dependency on the plugin.xml tab->
Now you can load the library using System.loadLibrary and use the classes from the plugin and from another plugin.
I decided not to modify plug-1, because it was created as a plug-in from an existing can, to which I could not learn how to add an activator. Instead, I chose the path to add .jar to plugin-2. See Adding Banners to the Eclipse Plugin for more discussion.
source share