kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.75k stars 348 forks source link

Unable to locate JNI library #383

Closed hamid064 closed 3 years ago

hamid064 commented 3 years ago

I exported a jar file using eclipse and when I came to the desktop to open it with a simple left-click nothing happen so to see what was happening I ran my jar file using CMD with this command line java -jar "C:\Users.....\Desktop\MyProgram.jar" the error I received was this: "com.github.kwhat.jnativehook.GlobalScreen SEVERE: Unable to locate JNI library at C:\Users.....\jnativehook-2.2.0.jar\com\github\kwhat\jnativehook\lib\windows\x86_64\JNativeHook.dll!

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Unable to locate JNI library at C:\Users.....\jnativehook-2.2.0.jar\com\github\kwhat\jnativehook\lib\windows\x86_64\JNativeHook.dll!

    at com.github.kwhat.jnativehook.GlobalScreen.<clinit>(GlobalScreen.java:91)
    at application_1_0.myprogram.GlobalKeyboardEventsListener(myprogram.java:107)
    at application_1_0.myprogram.initialize(MyProgram.java:61)
    at application_1_0.myprogram.<init>(MyProgram.java:41)
    at application_1_0.myprogram$1.run(MyProgram.java:28)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)"

I added the JNativeHook.dll to the path that it was looking for it, the problem Temprorerly solved I mean I could run it through CMD using java -jar "C:\Users.....\Desktop\MyProgram.jar" but still I can't run it with double click on my jar file. How can fix this issue? also, how can I change the path that this library looking for the JNativeHook.dll in it? I want to put it in my jar file.

I'm using eclipse 2020 -09 and my JDK 14.0.1 on windows 10 version 21H1 (OS Build: 19043.1288)

hamid064 commented 3 years ago

I put my jar file in the same dir where the .dll file is and the problem solved