1

I am developing a java app and I need to use jnativehook library. I have downloaded the .zip from https://code.google.com/p/jnativehook/downloads/list . There is a bin folder,src folder,build.xml,build.num and 3 .txt files when I extracted this folder.

I have included this library in my project by File -> project -> Java project from existing Ant file

And I have tried an example https://code.google.com/p/jnativehook/wiki/examples

But I get the following error

Exception in thread "main" java.lang.ExceptionInInitializerError
    at GlobalKeyListenerExample.main(GlobalKeyListenerExample.java:25)
Caused by: java.lang.RuntimeException: Unable to locate the native library.
    at org.jnativehook.GlobalScreen.loadNativeLibrary(GlobalScreen.java:462)
    at org.jnativehook.GlobalScreen.<init>(GlobalScreen.java:71)
    at org.jnativehook.GlobalScreen.<clinit>(GlobalScreen.java:53)
    ... 1 more

What location should I give in native library path?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
user3873909
  • 191
  • 1
  • 3
  • 15
  • For 1.1, the jar is included in the binary archive. In 1.2, there is only a single archive. If the library cannot find the correct native library, check that you have write access to the java.io.tmpdir location and that your Operating system and architecture are supported! – Alex Barker Aug 24 '14 at 16:12

1 Answers1

1

Looking through the source of GlobalScreen.loadNativeLibrary(), it seems that you get this exception when the library has failed to find the DLL on the java.library.path and instead tries to unpack it from the JAR, only to fail to find it.

Some options for fixing this include:

  • Checking you are running a supported platform.
  • Extract the right DLL from the JAR and place it on the java.library.path.

To use this library, you only need to include the JAR in your project. I don't like the sound of this part of your question:

I have included this library in my project by File -> project -> Java project from existing Ant file

Just download JNativeHook-1.1.4.zip, extract the ZIP and add the JNativeHook.jar JAR to your project.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • But there is no .jar file when i extracted.There is only build.xml file. – user3873909 Aug 21 '14 at 10:42
  • @user3873909 It sounds like you downloaded the src zip. Download exactly the file I've linked to in my answer and you'll find a JAR file in a "jar" folder. – Duncan Jones Aug 21 '14 at 10:43