YAJULEE (Yet Another Java UnsatisfiedLinkError Exception), even though the library exists and is in all paths

32 Views Asked by At

As the title says, I'm having a problem with a very simple (or so I thought) exercise in using JNI. I've gone through as many UnsatisfiedLinkError questions as I can stand here, but have found nothing that addresses this particular simple version of it. On Ubuntu 18.04.01 I've written a small, simple bit of JNI in C++, the important part of which is:

public class AJniClass {

    static {
        System.loadLibrary( "MyNativeLib" );
    }

}

This is compiled and linked into /usr/local/src/MyProject/lib/libMyNativeLib.so. The file is definitely present there. Then I have a Java program MyTest.java that instantiates AJniClass, which causes (or should cause) libMyNativeLib.so to be loaded when JAniClass is loaded. I have /usr/local/src/MyProject/lib in LD_LIBRARY_PATH. MyTest.java is successfully compiled and an executable MyTest.jar is created. When I attempt to run the jar a la...

java -jar MyTest.jar

...it fails with the following exception stack:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no libMyNativeLib.so in java.library.path: /usr/local/src/MyProject/lib:/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429) at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818) at java.base/java.lang.System.loadLibrary(System.java:1989) at MyTest.main(MyTest.java:37)

As you can see from the value of java.library.path the path to the library is known to the loader. And as I said, the .so file in question is most definitely present and accessible. I've been battling this for the better part of a day now, with my blood pressure reaching levels I've not seen for some time. Would anyone care to save me from an impending stroke and give me a clue as to what's going on here?

0

There are 0 best solutions below