Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading .DLL in Java

I want to call a .DLL method in Eclipse. Here is my code :

class TestJNI1 {
          public native void LireNoVersion();
          public void a() {
              System.loadLibrary("tttt.dll");
              LireNoVersion();
          }

        }

    public GlobalAction() {
        this.setBackground(GlobalPreferences.PANEL_BACKGROUND_COLOR);
        new TestJNI1().a();
    }

The problem is that I have this error on compilation :

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: tttt.dll  at java.lang.Runtime.load0(Unknown Source)  at java.lang.System.load(Unknown Source)

I already tried to :

  • Set arguments in Eclipse
  • Moving at root of project and System32 folder
  • Added the folder path in native library location in Eclipse
  • Changing the %PATH% in windows
  • Giving the absolute path as an argument
  • Trying with "tttt.dll", "./tttt.dll" and ".tttt.dll"
  • Call with System.loadLibrary(...) and System.load(...)

UPDATE

I tried to print the java.library.path and get a path. I put the dll in this path and the error message is more confusing now :

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: D:\My\Exact\Path\tttt.dll: Can't find dependent libraries

Here is the code to print the path :

String property = System.getProperty("java.library.path");
StringTokenizer parser = new StringTokenizer(property, ";");
while (parser.hasMoreTokens()) {
    System.err.println(parser.nextToken());
}
like image 784
Totem Avatar asked Apr 11 '26 15:04

Totem


1 Answers

The first problem was it couldn't find the dll because it wasn't in the path.

The second problem is that it can't find the dependencies on the dll that you are using. Your choices would seem to be

  1. Copy all dependent libraries to the dll location
  2. Run your code from the original dll location.
like image 182
Mike Murphy Avatar answered Apr 15 '26 05:04

Mike Murphy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!