1

I need to load a DLL is located somewhere out of my Jar file, but whenever I do try to run the Jar I get the following error:

java.lang.UnsatisfiedLinkError: E:\test.dll : Can't find dependent libraries
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)

The issue is not from the DLL, it's compiled to 64 bit machine as my PC is 64 bit, it has no dependencies, the issue only occurs when running from the Jar, when I run the application through my Eclipse it runs fine and everything loads fine.

The code code I using to load the DLL is:

File libraryFile = new File("E:\test.dll");
Runtime.getRuntime().load(libraryFile .getPath());

I used Eclipse to Jar the application.

EDIT I tried Jarring using different applications, such as Jar Maker and Jar Builder but nothing helps

EDIT 2 I tried to run this exact application, it works from the IDE but not from the Jarred file, tried moving the DLL but that didn't help as well:

public class Test {

    public static void main(String[] args) throws Exception {
        System.load("E:\\test.dll");
    }
}
WaliedYassen
  • 65
  • 1
  • 10

1 Answers1

1

Have you tried adding E:\test.dll in classpath.

rt.jar
  • 168
  • 10
  • I don't require the exact the library, It's dynamic loading system in end it calls the load method however, i can't add it to the classpath because the library name wont be known until the application run then request the library to be streamed to the user and loaded also the library name is different from user to user based on their PC and OS – WaliedYassen May 02 '17 at 03:36
  • Great, now things are getting clearer. Please have a look at following http://stackoverflow.com/questions/15635945/java-jni-load-native-dll-with-circular-dependency – rt.jar May 02 '17 at 03:41
  • Didn't help, Let me be more clear, the issue only occurs if i run from the jar, but when using anything else it would work, i think the code is pure fine but the issue lays in the jar maybe? – WaliedYassen May 02 '17 at 03:51
  • instead of Runtime.getRuntime().load(libraryFile .getPath()); could you check with System.load(new File("E:\test.dll")); – rt.jar May 02 '17 at 03:59
  • Thanks for taking your time trying to help, but that didn't work :/ – WaliedYassen May 02 '17 at 04:01
  • 1
    Based [on this answer](http://stackoverflow.com/questions/6092200/how-to-fix-an-unsatisfiedlinkerror-cant-find-dependent-libraries-in-a-jni-pro) the class path is not used to find libraries – MadProgrammer May 02 '17 at 04:08
  • Now lets go one step at a time: `code` public class LoadDLL{ public static void main(String[] args){ System.load(args[0]); System.out.println("Loaded...."+args[0]); } } I compiled this class loaded a dll works perfectly. No IDE used. – rt.jar May 02 '17 at 04:25