Search code examples
javajava-native-interface

LibraryNotFoundException while running java code that invokes dlls


I have written a code that requires 2 dll's at runtime.I have those dll files in C:\Program Files\Java\jdk1.6.0_01\jre\bin. I have set the environment variable PATH accordingly. It compiled successfully and then while running it gives the following error:

Exception in thread "main" java.lang.ExceptionInInitializerError
        at teamdev.jxcapture.Capture.captureActiveWindow(Unknown Source)
        at ppb.activewindow.execute(activewindow.java:24)
        at ppb.activewindow.main(activewindow.java:68)
Caused by: com.jniwrapper.LibraryNotFoundException: Cannot find JNIWrapper nativ
e library (jniwrap.dll) in java.library.path: C:\Program Files\Java\jdk1.6.0_01\
jre\bin\jniwrap.dll

Could anybody please help me to resolve this problem?


Solution

  • The value of java.library.path should be the directory containing the DLLs, not the filename of the DLLs themselves. It looks like your java.library.path is set to

    C:\Program Files\Java\jdk1.6.0_01\jre\bin\jniwrap.dll
    

    instead of

    C:\Program Files\Java\jdk1.6.0_01\jre\bin