Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » integrate jni library (may run as java application and cannot in plugin)
integrate jni library [message #531423] Tue, 04 May 2010 20:07 Go to next message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
Hi, I defined external jar with jni library as separate plugin A, as described in the following links:
http://www.vogella.de/articles/EclipseJarToPlugin/article.ht ml
http://www.eclipsezone.com/eclipse/forums/t49342.html
I have a plugin B, dependent on plugin A.
the jni method succeess when I run main as java application and fails when I run it within plugin.
External plugin has one native and one regular method. Regular method always success. Native library is also success to load - I get "-I- Success to load". The interface of native library is ok - I checked with javah.
package bbb;
public class aaa {
  public final static native long someMethod(String jarg1); // native method
  public static void otherMethod() {        // regular method
        System.out.println("Jar containing bbb.aaa.otherMethod() is loaded ok");
}};

The class calling them:
public class RTL {	
   static {
            System.loadLibrary("kuku");
            System.out.println("-I- Success to load native library");
     }
public static void buildDesign() {
     aaa.otherMethod(); // call regular method - ok
     aaa.someMethod(); // call native method - FAILS!!!
}
public static void main(String argv[]) {
     aaa.otherMethod(); // call regular method - ok
     aaa.someMethod(); // call native method - ok
}

Any ideas will be very appreciated!
Re: integrate jni library [message #531498 is a reply to message #531423] Wed, 05 May 2010 09:09 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
How does it fails? Can you post the Exception? Is it a UnsatisfiedLinkedError? Is your dll file at the root of the plugin ? Do you have set the dll to your classpath?

Greetz
Thomas
Re: integrate jni library [message #531513 is a reply to message #531498] Wed, 05 May 2010 09:45 Go to previous messageGo to next message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
Thanks a lot for reply.
It fails with
java.lang.UnsatisfiedLinkError: bbb.aaa.someMethod(Ljava/lang/String;)J
	at bbb.aaa.someMethod(Native Method)

On Linux x64, my shared library *.so is on the root of plugin A.
The shared library is loaded, I see the message: "-I- Success to load native library". It fails on invocation of the native method.
In the properties of the plugin A (the one having native library)
Java Build Path -> Libraries -> <my jar> Native library location = root of plugin A.
In the properties of the plugin B (the one dependent on A)
Java Build Path -> Libraries -> Plugin Dependencies -> Plugin A Native library location = none, not modifiable
Re: integrate jni library [message #531567 is a reply to message #531513] Wed, 05 May 2010 12:01 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

in bundles, you can use Bundle-NativeCode to specify a dll/.so to load.
Google for it, or here's a handy link:
http://litrik.blogspot.com/2007/08/secrets-of-bundle-nativec ode.html

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: integrate jni library [message #532031 is a reply to message #531423] Thu, 06 May 2010 20:04 Go to previous messageGo to next message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
Hi, may you recommend example or tutorial with eclipse plugin and jni integration on Linux. Java application works with my jni library without problems.
Tried Bundle-NativeCode, remove loadLibrary statement. The plugin A stopped to load at all.
Thanks a lot.
Re: integrate jni library [message #532349 is a reply to message #531423] Sat, 08 May 2010 17:25 Go to previous messageGo to next message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
After more investigation it looks as a bug in eclipse 3.4.1 that was fixed in 3.5 version on Linux 64.
I worked with debugger and found:
System.loadLibrary("mylibrary");
Loads the library, where class loader is the loader of the calling class. It adds the library to the list of nativeLibraries .
ClassLoader::loadLibrary0...
       ClassLoader loader =
	    (fromClass == null) ? null : fromClass.getClassLoader();
      ...
       LoadedLibraryNames.addElement(name);
       libs.addElement(lib);


Where call to native method gets to method findNative with different classLoader and it doesn't see any native library in the nativeLibraries. Both run in the same thread.
  static long findNative(ClassLoader loader, String name) {
        Vector libs =
            loader != null ? loader.nativeLibraries : systemNativeLibraries;
        synchronized (libs) {
            int size = libs.size();
            for (int i = 0; i < size; i++) {


In order to reproduce - create simple plugin project with "Hello Word" command and load native library in the SampleHandler, call native method in the execute method.
Thanks, regards, Stella
Re: integrate jni library [message #532371 is a reply to message #532349] Sun, 09 May 2010 06:54 Go to previous message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
In eclipse 3.5 both loaders are the same, and the application works.
Previous Topic:RCP Rich Jboss Client
Next Topic:Jboss
Goto Forum:
  


Current Time: Wed May 08 11:36:43 GMT 2024

Powered by FUDForum. Page generated in 0.03257 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top