1

I want to use System.load() to load a DLL file that is within the JAR. I tried

URL dllPath = MyClass.class.getResource("path/to/dll/folder");
System.load(dllPath.getPath().replace("file:/","")+"/"+dllName);

I get:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: path/to/jar/thejar.jar!/path/to/dll

Any ideas?

commandertuna
  • 104
  • 1
  • 13
wil
  • 11
  • 2
  • What makes you think that path including `!` and relative path within the JAR archive is understood by the method? I would expect it to only accept filesystem paths. – Jiri Tousek Jun 12 '18 at 12:55
  • this function gives me the right path, its system.load() who apparently can't access to a ressource in a jar file, idk why – wil Jun 12 '18 at 12:56
  • 1
    @wil That's correct, because it's not a path on the file system. A file inside the JAR archive is not accessible with just a path, you need to extract it to temp and pass the path of the temp file to `System.load` – BackSlash Jun 12 '18 at 12:58
  • How do I extract the dll to a temporary file ? – wil Jun 12 '18 at 13:02
  • @wil Have a look [here](https://github.com/adamheinrich/native-utils/blob/master/src/main/java/cz/adamh/utils/NativeUtils.java) – BackSlash Jun 12 '18 at 13:03
  • thank you BackSlash – wil Jun 12 '18 at 13:12
  • Look here: https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo031 – Oo.oO Jun 12 '18 at 13:52

0 Answers0