Search code examples
javanativeloadlibraryunsatisfiedlinkerror

load java native file lib


I would like to use some native files and use some files out of an android project. I need this files for my own java project and need to import the lib.

I am trying to load the lib with:

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

The lib file "libmrclient_java.so" is in this folder: "/libs/armeabi/".

When I run the project following error appears:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no mrclient_java in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)

I dont know how to configure the CLASSPATH or whatever to solve this problem. I am not using android for this project. The android project itself runs perfectly.

EDIT:

I found this Question: How to set the java.library.path from Eclipse, but the same error still appear.


Solution

  • You have to add java.library.path to your command line that runs java. Something like the following:

    java -cp YOURCLASSPATH -Djava.library.path=/libs/armeabi/ com.compnay.Main

    Classpath is for loading java classes only. Library path is for loading native libraries.