- java.lang.UnsatisfiedLinkError no *****.dll in java.library.path
- 14 Answers 14
- What is the cause of an UnsatisfiedLinkError?
- 3 Answers 3
- Windows, JNA: Cannot load native library — UnsatisfiedLinkError
- How to fix an UnsatisfiedLinkError (Can’t find dependent libraries) in a JNI project
- 17 Answers 17
- Why do I get java.lang.UnsatisfiedLinkError: Unable to load library?
- 4 Answers 4
java.lang.UnsatisfiedLinkError no *****.dll in java.library.path
How can I load a custom dll file in my web application? I’ve tried the following:
- Copied all required dlls in system32 folder and tried to load one of them in Servlet constructor System.loadLibrary
- Copied required dlls into tomcat_home/shared/lib and tomcat_home/common/lib
All these dlls are in WEB-INF/lib of the web-application
14 Answers 14
In order for System.loadLibrary() to work, the library (on Windows, a DLL) must be in a directory somewhere on your PATH or on a path listed in the java.library.path system property (so you can launch Java like java -Djava.library.path=/path/to/dir ).
Additionally, for loadLibrary() , you specify the base name of the library, without the .dll at the end. So, for /path/to/something.dll , you would just use System.loadLibrary(«something») .
You also need to look at the exact UnsatisfiedLinkError that you are getting. If it says something like:
then it can’t find the foo library (foo.dll) in your PATH or java.library.path . If it says something like:
then something is wrong with the library itself in the sense that Java is not able to map a native Java function in your application to its actual native counterpart.
To start with, I would put some logging around your System.loadLibrary() call to see if that executes properly. If it throws an exception or is not in a code path that is actually executed, then you will always get the latter type of UnsatisfiedLinkError explained above.
As a sidenote, most people put their loadLibrary() calls into a static initializer block in the class with the native methods, to ensure that it is always executed exactly once:
What is the cause of an UnsatisfiedLinkError?
When i am trying to run my program it is giving the following error
3 Answers 3
From the Javadoc:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
It is an error related to JNI. loadJacobLibrary is trying to load the native library called jacob-1.14.3-x86 and it is not found on the path defined by java.library.path. This path should be defined as a system property when you start the JVM. e.g.
On Windows, the actual native library file will be called jacob-1.14.3-x86.dll while on Linux it would be called libjacob-1.14.3-x86.so
You need the jacob-1.14.3-x86 library on your java library path.
On windows, this would be jacob-1.14.3-x86.dll.
This is a binary file which is used by java to run native methods. It’s probably required by some library (jar) you’re using.
In here you can see not only a jar, but also the binary required by the jar. Pick the one for your platform.
There are two things that cause UnsatisfiedLinkError. One is when System.loadLibrary() fails to load the library, the other is when the JVM fails to find a specific method in the library. The text of the error message itself will indicate which is the case.
The error which you describe clearly cannot find the library at all. As the others have said, include it in your Java library path.
The other error—when the library can be found but the method within the library is not found—looks as follows:
In this case you either have the wrong method name, or will have to go back and add the method and recompile the code.
Windows, JNA: Cannot load native library — UnsatisfiedLinkError
I am using Java 7 on Windows 7 and am trying to use Java JNA (Java Native Access) (4.2.2) [ link: https://github.com/java-native-access/jna ] to provide access to a C language native library. I have done this on a Linux system and have no problems finding and loading the library.
I am using the suggested technique of setting the system property jna.library.path to the path where the library is located. As mentioned above, this works on Linux, but on Windows I cannot get it to find and load the library.
On the Windows platform, the library comes in both 32 and 64 bit variants (I’m trying to use the 32-bit), with both .lib and .dll files.
I also set the system properties jna.debug_load and jna.debug_load.jna to true as suggested to watch how JNA does its thing.
I have tried the following to no avail:
- System.setProperty(«jna.library.path», «C:\Program Files (x86)\VMware\VMware VIX»); (Windows style path)
- System.setProperty(«jna.library.path», «C:/Program Files (x86)/VMware/VMware VIX»); (UNIX style path)
- I placed the library in a path that has no spaces in it.
- I added the library name on the path (with and without file extension). E.g. «C:\Program Files (x86)\VMware\VMware VIX\VixAllProductsDyn». (VixAllProductsDyn.dll)
When I make an attempt, I can see the debug information on the Java console. Oddly, it tries the exact path to where the library file sits — and yet does not find it.
If anyone has run into this and knows anything about solving the problem, it would be much appreciated.
How to fix an UnsatisfiedLinkError (Can’t find dependent libraries) in a JNI project
I’m working on a Java project that uses the JNI. The JNI calls a custom library that I’ve written myself, let’s say mylib.dll, and that depends on a 3rd party library, libsndfile-1.dll.
When I run my program it crashes with
I’ve searched this site (and others) and I’ve tried a number of fixes:
I ran dependency walker. DW gave a couple of warnings — that two libraries required by libsndfile, MPR.DLL and SHLWAPI.DLL, had «unresolved imports» — but the DW FAQ said that these warnings could be safely ignored.
I fixed the method names in mylib.dll, as suggested here. The method names had somehow gotten mangled by the compiler, but I added linker flags and the dll method names now match those in my jni header file exactly.
I put all of these DLLs in the same directory — the same directory as the .jar that calls them — to ensure that they’re on the right PATH.
Does anyone have any idea what’s going on?
I’m doing my development in Visual Studio 2010 on a MacBook pro (via Parallels). I’m doing my testing in Windows XP on a toshiba laptop.
17 Answers 17
I’m pretty sure the classpath and the shared library search path have little to do with each other. According to The JNI Book (which admittedly is old), on Windows if you do not use the java.library.path system property, the DLL needs to be in the current working directory or in a directory listed in the Windows PATH environment variable.
Update:
Looks like Oracle has removed the PDF from its website. I’ve updated the link above to point to an instance of the PDF living at University of Texas — Arlington.
Also, you can also read Oracle’s HTML version of the JNI Specification. That lives in the Java 8 section of the Java website and so hopefully will be around for a while.
Update 2:
At least in Java 8 (I haven’t checked earlier versions) you can do:
to find the shared library search path. Look for the value of the java.library.path property in that output.
I want to inform this interesting case, after tried all the above method, the error is still there. The weird thing is it works on a Windows 7 computer, but on Windows XP it is not. Then I use dependency walker and found on the Windows XP there is no VC++ Runtime as my dll requirement. After installing VC++ Runtime package here it works like a charm. The thing that disturbed me is it keeps telling Can’t find dependent libraries, while intuitively the JNI dependent dll is there, however it finally turns out the JNI dependent dll requires another dependent dl. I hope this helps.
You need to load your JNI library.
System.loadLibrary loads the DLL from the JVM path (JDK bin path).
If you want to load an explicit file with a path, use System.load()
If you load a 32 bit version of your dll with a 64 bit JRE you could have this issue. This was my case.
Please verify your library path is right or not. Of course, you can use following code to check your library path path: System.out.println(System.getProperty(«java.library.path»));
You can appoint the java.library.path when launching a Java application:
Did have identical problem with on XP machine when installing javacv and opencv in combination with Eclipse. It turned out that I was missing the following files:
Once these were installed, the project compiled and ran OK.
- Short answer: for «can’t find dependent library» error, check your $PATH (corresponds to bullet point #3 below)
- Long answer:
- Pure java world: jvm uses «Classpath» to find class files
- JNI world (java/native boundary): jvm uses «java.library.path» (which defaults to $PATH) to find dlls
- pure native world: native code uses $PATH to load other dlls
I found a great article by some friends at keepsafe that went through the same thing I did. It worked for me, so hopefully it helps you out as well! Have a read if you’re interested (The Perils of Loading Native Libraries on Android) or just use
I used to have exactly the same problem, and finally it was solved.
I put all the dependent DLLs into the same folder where mylib.dll was stored and make sure the JAVA Compiler could find it (if there is no mylib.dll in the compilation path, there would be an error reporting this during compiling). The important thing you need to notice is you must make sure all the dependent libs are of the same version with mylib.dll, for example if your mylib.dll is release version then you should also put the release version of all its dependent libs there.
Hope this could help others who have encountered the same problem.
I had the same issue, and I tried everything what is posted here to fix it but none worked for me. In my case I’m using Cygwin to compile the dll. It seems that JVM tries to find the JRE DLLs in the virtual Cygwin path. I added the the Cygwin’s virtual directory path to JRE’s DLLs and it works now. I did something like:
SET PATH=»/cygdrive/c/Program Files/Java/jdk1.8.0_45″;%PATH%
In my situation, I was trying to run a java web service in Tomcat 7 via a connector in Eclipse. The app ran well when I deployed the war file to an instance of Tomcat 7 on my laptop. The app requires a jdbc type 2 driver for «IBM DB2 9.5». For some odd reason the connector in Eclispe could not see or use the paths in the IBM DB2 environment variables, to reach the dll files installed on my laptop as the jcc client. The error message either stated that it failed to find the db2jcct2 dll file or it failed to find the dependent libraries for that dll file. Ultimately, I deleted the connector and rebuilt it. Then it worked properly. I’m adding this solution here as documentation, because I failed to find this specific solution anywhere else.
Why do I get java.lang.UnsatisfiedLinkError: Unable to load library?
I am trying to call a .dll file from my Java app using JNA. I am getting the following exception:
Exception in thread «main» java.lang.UnsatisfiedLinkError: Unable to load library ‘C:\Windows\System32\foo.dll’: The specified module could not be found.
Both the .dll and my jdk are 32 bit (OS_ARCH=»i586″) although I am running it on a 64 bit Windows 7 PC.
The .dll is in the System32 folder.
I am using Eclipse and have added the System32 folder to the Native library location in the JRE System library under the Libraries tab in the Java Build Path Properties (although I don’t think this should be necessary).
I would be grateful for any help or suggestions.
Thanks,
-Munk.
4 Answers 4
This is down to the file system redirector. You are executing under the WOW64 emulator that emulates 32 bit Windows on a 64 bit system. Under WOW64, the system32 is redirected to SysWOW64 . You’ll need to put your DLL there.
With that said, the system directory is owned by, and private to, the system. You are expected not to put DLLs into the system directory. You should find a way to put your DLL in some other location.
Another reason for error is that the dll is only supported for 32 version not for 64 bit OS. You have to confirm the dll vendor.
my os is windows-x64 and my jdk is x64.So the problem is same with you. my solution is you must install jdk-x86,and put you dll into the jdk-x86/bin directory.
Three possible reasons for this issue, if the dll file is not broken:
32 bit 64 bit Compatibility. 32bit dll can only be running on a 32bit jdk or jre. By using Cygwin command file we can tell if a dll is 32bit or 64bit.
the dll is not lacated in the right path, so java cannot locate it. Generally speaking we can use some absolut path other than System32 to ensure that the path is right.
the dll that we are loading is requires other dlls.
How can we handle the 3rd possibility:
using JNI’s System.loadLibrary() mthod can give me more hint, compared with JNA. It may says something like: Exception in thread «main» java.lang.UnsatisfiedLinkError: MyLibrary.dll: Can’t find dependent libraries. It means some libraries MyLibrary.dll depends is missing. By using dependency walker we can tell what dlls are needed.
By loading these dlls before the dll that we want to load, we can solve this issue.