Search code examples
javajava-native-interfacemanifestexecutable-jar

JNI Unsatisfied link error in distributed jar


I have a java project that connects to a fingerprint scanner through a JNI library. I have the project running perfectly in netbeans with the jni files in the root directory of the java project. The problem occurs when I try and package it as a jar. Im having this error:

C:\Users\dwake\Desktop\OnceAgain\TestJob\dist>java -jar TestJob.jar
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no scannerJNI in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at scanner.scannerGUI.<clinit>(Unknown Source)
    at scanner.main$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
    at java.awt.EventQueue.access$000(EventQueue.java:102)
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

I know this is caused by a library file not being in the correct directory or not being found by the java virtual machine. How would I get my JNI libraries to compile with the jar?

P.S. I have tried opening the jar with 7zip and placing the .dll files in the jar but this hasnt helped.


Solution

  • Try this:

    java -Djava.library.path=/path/to/dlls/ -jar TestJob.jar