0

I have the following Java class that invokes a native library on Linux (/usr/local/lib/libCAPJni.so):

public class MyClass {
    private native float runCAP(String name, int[] data);

    private static final String LD_LIBRARY_PATH = "/usr/local/lib";

    static {
        System.setProperty("java.library.path", LD_LIBRARY_PATH);
        System.loadLibrary("CAPJni");
    }
    ...
}

The native library libCAPJni.so is located in /usr/local/lib. I also set this lib path in my Eclipse's Build Path -> Native library location. However when I launched my application in Eclipse, I got the following error:

java.lang.UnsatisfiedLinkError: no CAPJni in java.library.path

This seems to be caused by that the native lib is not found in /usr/local/lib directory. But if I directly run the following in command line:

java -Djava.library.path=/usr/local/lib MyClass

It runs fine without any problem. Why can't my Tomcat web application find the native library?

tonga
  • 11,749
  • 25
  • 75
  • 96

1 Answers1

0

Specifying the native library path in Eclipse should definitely work. However, it does NOT work to specify the library path at runtime with setting the system property. The library path must be known and set when booting the jvm. I haven't worked with tomcat yet but as you mentioned it, make sure that tomcat starts with this parameter as well which might be your problem here.

EDIT: As stated here it might actually be possible to change the library path later on. But as this is a hack and messes with the classloader it is most likely not a good idea to use that in the tomcat environment.

Community
  • 1
  • 1
Nithanim
  • 443
  • 5
  • 6