简体   繁体   中英

Java JNI UnsatisfiedLinkError for static load

I need to link a JNI dll to my Java app, this is the code:

static
    {
        System.load("c:\\boca\\java\\BocaWorld.dll");
    }

And this is the error

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\boca\java\BocaWorld.dll: Can't find dependent libraries

I could solve putting all dlls into the JRE/bin folder, but why the first method doesn't work? I don't want to copy all dlls into JRE folder.

You've provided only the path to the single native library, all it's dependencies are searched under the predefined paths, not the path, you've set for concrete library. You can try to set java.library.path system property for your application, pointing to the folder, containing your native libraries. This property is used to locate the native libs.

You can set it via command line arguments, like:

java -Djava.library.path=<path_to_libs> <main_class>

Or via System.setProperty , like:

System.setProperty(“java.library.path”, “/path/to/library”);

Furthermore, you are able to skip the path to the lib, since you set this property, becase JVM will search for it under the path, you've set, so it could be like:

static
{
    System.setProperty(“java.library.path”, “c:\\boca\\java\\”);
    System.loadLibrary("BocaWorld.dll");
}

But don't forget, that java.library.path can contain some paths already, so you can add your new path with ; as separator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM