Sunday 19 May 2013

java.lang.UnsatisfiedLinkError: no dll in java.library.path Exception Java

Java - Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path

"Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path" is a frusttrating exception you will get if your application is using native library from java.lang.System.loadLibarray() method. I was writing  some Tibco Rendezvous Messaging code which uses some windows specific dll and I got "java.lang.UnsatisfiedLinkError: no *.dll in java.library.path". here we will see real cause of "Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path" and how to fix this Exception in Java.

Cause of java.lang.UnsatisfiedLinkError: no dll in java.library.path:

Exception in thread When you load native library like .so on Linux or .dll on Windows using System.loadLibrary() it looks for those shared library in both PATH environment variable and java.libarary.path system property, if it doesn't find shared library it throws "Exception in thread "main" java.lang.UnsatisfiedLinkError: no in java.library.path". now trick is that in Windows it picks up dll form System32 folder and most of the time System32 exits in path so we don't usually come up with this problem. anyway if you are repeatedly getting this Error than you can try following step which may help you to resolve java.lang.UnsatisfiedLinkError in your java application.

Solution of "Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path"

1) Check your PATH for Java , whether it contains required dll or not.
2) Verify your java.library.path in case you have set it for required dll.
3) Run your java application with command : java -Djava.library.path= "your dll path"
4) Try specifying base name for the library and loading library using System.loadLibaray("name) where name is without dll.
5) Linux loads dynamic linked library(.so) from LD_LIBRARY_PATH so you may want to have your shared library directory included in LD_LIBRARY_PATH e.g.
6) load library by providing absolute path like "C:/WINNT/system32/digest.dll"

export LD_LIBRARY_PATH=/shared library (.so)

Main point is JVM should find your dll and providing explicitly path with -Djava.library.path always help me.
Some other points worth noting while working with System dependent libraries:
1) They make java code platform dependent.
2) System.loadLibrary() is equivalent to Runtime.getRuntime.loadLibary().
3) load System.loadLibary(libary) in static initalizer block so that it only gets loaded when containing class gets loaded and
Another worth noting point is the actual error message java.lang.UnsatisfiedLinkError throws:

if it shows  "Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path"  means JVM is not able to locate and load library.

if it shows thread "main" java.lang.UnsatisfiedLinkError: com......' i.e. prints class or method name than may be something is wrong with library itself like half copied dll.
Some time you may also get

Exception in thread "main" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: digest.dll
        at java.lang.Runtime.load0(Runtime.java:767)
        at java.lang.System.load(System.java:1003)

to solve this just provide absolute path for library and you will be fine.
That’s all on how to fix  Exception in thread "main" java.lang.UnsatisfiedLinkError: no dll in java.library.path" , share your experience if you have faced this java.lang.UnsatisfiedLinkError before.
Other Java debugging tutorial you may like

How to fix java.lang.UnSupportedClassVersionError in Java

How to debug Java program in Eclipse – Java Debugging tips

How to remote debug Java application in Eclipse

Difference between ClassNotFoundException vs NoClassDefFoundError in Java

How to resolve java.lang.ClassNotFoundException in Java

How to fix Java.lang.OutOfMemroyError in Tomcat Server

How to solve Invalid Column Index Exception in Java JDBC

How to solve java.util.nosuchelementexception hashtable enumerator

How to fix java.lang.nosuchmethoderror main in Java

Please share with your friends if like this article

No comments:

Post a Comment