0

I am trying to deploy my application that invokes native calls using JNA library, but I get the following exception. Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'myCustomDLL': Native library (win32-x86-64/myCustomDLL.dll) not found in resource path ([myproject/target/classes/, ...some jars...])

What do I need to do in order to invoke the function correctly?

Any help much appreciated

Dan Smith
  • 423
  • 2
  • 5
  • 17
  • JNA will attempt to load from `jna.library.path` and if not there will look in your resource path according to [this strategy](http://twall.github.io/jna/4.1.0/com/sun/jna/NativeLibrary.html). – technomage Oct 24 '14 at 10:12

3 Answers3

0

You must put your dll library (with native code) on application java.library.path.

See : http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/

Edit:

Post your project layout here. And how you run your app.

Grzesuav
  • 459
  • 2
  • 10
  • I added my dll in /webapps/classes folder, but still does not pick it up. I am still getting the same error. – Dan Smith Oct 22 '14 at 15:55
  • Here is the layout of my application: 1) The DLL location: /webapps/classes\myCustomDLL.dll 2) Inside my Java Folder, I do the following: CLibrary INSTANCE3 = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "myCustomDLL" : "c"), CLibrary.class); – Dan Smith Oct 22 '14 at 16:14
  • Have you check your java.library.path (check link which I posted)? – Grzesuav Oct 22 '14 at 16:17
  • What is the
    > Is that the main class for my application where the actual dll is loaded?
    – Dan Smith Oct 22 '14 at 16:23
  • In this context is a class containing public static void main() method (java class), not native class. – Grzesuav Oct 22 '14 at 16:27
  • I am deploying my app as a war file in Tomcat and sending a request via SoapUI. As soon as loadLibrary call happens, it fails with that error – Dan Smith Oct 22 '14 at 18:10
  • Also, that my custom DLL is dependent on other DLLs – Dan Smith Oct 22 '14 at 18:11
  • All dll must be on java.library.path of Tomcat java. Could you check how java.library.path looks like on this server, copy all neccesary dll's to this location and check again ? – Grzesuav Oct 22 '14 at 18:13
  • Also you could use http://one-jar.sourceforge.net to deploy whole app as one jar with native libraries. – Grzesuav Oct 22 '14 at 18:14
0

Check whether the DLL is executable. Check the dependant DLLs are all executable.

With windows explorer, right click on DLL -> property -> security and verify execution rights.

Vouze
  • 1,678
  • 17
  • 10
0

Actually I found the answer to this. Basically, I needed to install Microsoft Visual C++ Redistributable package to install all the necessary DLLs needed for JNA to work. Thanks for other responses to this question.

Dan Smith
  • 423
  • 2
  • 5
  • 17