Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading DLL in Java - Eclipse - JNI

I am trying to load a dll in java using the following code System.loadLibrary("mydll");

The project is placed in D:\development\project\ and i have placed the dll on D:. I then gave following VM argument in eclipse configuration -Djava.library.path=D:/

But when i run i get UnsatisifiedLinkerError. After googling a bit, I used System.load("D:\mydll.dll");

but again getting the same problem, could someone can help?

like image 416
x.509 Avatar asked Mar 29 '10 03:03

x.509


People also ask

Can we use DLL in Java?

To use an arbitrary DLL from Java you usually have to create an adapting DLL with the conventions of JNI that itself loads the "target" DLL and calls the required functions. To generate the correct headers for your adapter DLL you can use the tool javah shipped with the JDK.

Where is my Java library path?

Go to Project properties->Java Build Path->Source. You'll find a list of source-folders. Each entry under the the Source tab has Native library locations.


1 Answers

I got my error resolved by using the following:

   static {
    try {
        System.loadLibrary("myDLL");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Instead of using System.load("myDLL.dll")

like image 119
Mansi Avatar answered Oct 30 '22 15:10

Mansi