unable to use .dll file in the Java code [duplicat

2019-08-26 01:36发布

问题:

Possible Duplicate:
how to use .dll files in java code?

The dll file, I am using, is giving error:

The error message is:

java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: Eagleye_parser
    at java.lang.Runtime.load0(Runtime.java:767)
    at java.lang.System.load(System.java:1005)
    at test.TestDllJava.<clinit>(TestDllJava.java:15)
Exception in thread "main" 

This is the code:

public class TestDllJava {

    private static native String[] eagleye_fmu(String A);

    public static void main(String[] args){
        String[] ag = null;
        String parameter =  null;
        parameter = "356188030442449 10250000 0001F464 0000EB34 0002CC7D 4xA0";
         ag = eagleye_fmu(parameter);
        System.out.println(ag);
    }

    static { 
        System.load("Eagleye_parser");
    } 
}

Please correct me, where I am doing wrong.

回答1:

As the docs of load() specify:

Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

A better approach without stating an absolute path to library is by using loadLibrary() or maybe load(mapLibraryName(..)).

In Eclipse, you can specify native library folder in your project via project Properties -> Java build Path -> tab Libraries -> expand your System Library, click Native Library Location. Eclipse will build java.library.path for you and loadLibrary() will then see it easily.