UmeshChoudhari / jnativehook

Automatically exported from code.google.com/p/jnativehook
0 stars 0 forks source link

JDK7 on Mac does not work #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Import the latest jar into a JDK7 app on Mac.

What is the expected output? What do you see instead?
Nothing

Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at keymusix.core$eval5$loading__4784__auto____6.invoke(core.clj:1)
    at keymusix.core$eval5.invoke(core.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6511)
    at clojure.lang.Compiler.eval(Compiler.java:6501)
    at clojure.lang.Compiler.load(Compiler.java:6952)
    at clojure.lang.RT.loadResourceScript(RT.java:359)
    at clojure.lang.RT.loadResourceScript(RT.java:350)
    at clojure.lang.RT.load(RT.java:429)
    at clojure.lang.RT.load(RT.java:400)
    at clojure.core$load$fn__4890.invoke(core.clj:5415)
    at clojure.core$load.doInvoke(core.clj:5414)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5227)
    at clojure.core$load_lib.doInvoke(core.clj:5264)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$load_libs.doInvoke(core.clj:5298)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:603)
    at clojure.core$require.doInvoke(core.clj:5381)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at user$eval1.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:6511)
    at clojure.lang.Compiler.eval(Compiler.java:6500)
    at clojure.lang.Compiler.eval(Compiler.java:6477)
    at clojure.core$eval.invoke(core.clj:2797)
    at clojure.main$eval_opt.invoke(main.clj:297)
    at clojure.main$initialize.invoke(main.clj:316)
    at clojure.main$null_opt.invoke(main.clj:349)
    at clojure.main$main.doInvoke(main.clj:427)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
    at org.jnativehook.GlobalScreen.loadNativeLibrary(Unknown Source)
    at org.jnativehook.GlobalScreen.<init>(Unknown Source)
    at org.jnativehook.GlobalScreen.<clinit>(Unknown Source)
    ... 37 more

What version of the product are you using? On what operating system?
JNativeHook-1.1.0_rc3 on Mac OS X 10.7.4 with JVM version 1.7.0_04

Please provide any additional information below.

Works just fine on 6.

I tried building it from SVN on my Mac, but that did not end well.

compile-native:
     [echo] Creating JNI Headers...
    [javah] [No need to update file RegularFileObject[/Users/pepijndevos/svn/jnativehook/src/native/jni/org_jnativehook_GlobalScreen.h]]
     [echo] Compiling C source...
     [echo] Applying gcc on the following files: common/NativeErrors.c;common/NativeGlobals.c;jni/org_jnativehook_GlobalScreen.c;osx/NativeHelpers.c;osx/NativeThread.c;osx/NativeToJava.c;osx/OSXInputHelpers.c
    [apply] In file included from /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.h:36,
    [apply]                  from /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:19:
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:45:20: error: jni_md.h: No such file or directory
    [apply] In file included from /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.h:36,
    [apply]                  from /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:19:
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:63: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jsize’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:122: error: expected specifier-qualifier-list before ‘jbyte’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:220: error: expected specifier-qualifier-list before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1869: error: expected specifier-qualifier-list before ‘jint’
    [apply] cc1: warnings being treated as errors
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1874: warning: struct has no members
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1877: error: expected specifier-qualifier-list before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1881: warning: struct has no members
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1895: error: expected specifier-qualifier-list before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1934: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1937: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1940: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1944: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jint’
    [apply] /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h:1947: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    [apply] In file included from /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:20:
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeGlobals.h:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jni_version’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c: In function ‘ThrowFatalError’:
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:28: error: ‘const struct JNIInvokeInterface_’ has no member named ‘GetEnv’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:28: error: ‘jni_version’ undeclared (first use in this function)
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:28: error: (Each undeclared identifier is reported only once
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:28: error: for each function it appears in.)
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:29: error: ‘const struct JNINativeInterface_’ has no member named ‘FatalError’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c: In function ‘ThrowException’:
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:37: error: ‘const struct JNIInvokeInterface_’ has no member named ‘GetEnv’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:37: error: ‘jni_version’ undeclared (first use in this function)
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:39: error: ‘const struct JNINativeInterface_’ has no member named ‘FindClass’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:42: error: ‘const struct JNINativeInterface_’ has no member named ‘ThrowNew’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:46: error: ‘const struct JNINativeInterface_’ has no member named ‘DeleteLocalRef’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:49: error: ‘const struct JNINativeInterface_’ has no member named ‘FindClass’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:52: error: ‘const struct JNINativeInterface_’ has no member named ‘ThrowNew’
    [apply] /Users/pepijndevos/svn/jnativehook/src/native/common/NativeErrors.c:56: error: ‘const struct JNINativeInterface_’ has no member named ‘DeleteLocalRef’

BUILD FAILED
/Users/pepijndevos/svn/jnativehook/build.xml:685: apply returned: 1

Original issue reported on code.google.com by pepijndevos on 27 Aug 2012 at 2:54

GoogleCodeExporter commented 9 years ago
Looks like it did not find the correct include file.  Can you attach the 
generated build.properties file?

Original comment by a...@1stleg.com on 27 Aug 2012 at 3:35

GoogleCodeExporter commented 9 years ago
First off, do i really need to build it myself to have it work with JDK7?

I manually set JAVA_HOME to point to my JDK7 VM.

#auto-generated by ant configure
#Mon, 27 Aug 2012 16:46:37 +0200

java.cc=modern
java.target=1.5
native.cc=gcc
native.cc.args=-c -m64 -arch x86_64 -mtune\=generic -O2 -fomit-frame-pointer 
-pipe  -fPIC -Wall -Wextra -Werror -std\=c99 -pedantic -pthread   
-DCOREFOUNDATION -DIOKIT -I/Users/pepijndevos/svn/jnativehook/src/native/common 
-I/Users/pepijndevos/svn/jnativehook/src/native/jni -I/usr/lib 
-I/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include
native.cc.args2=-o
native.ld=gcc
native.ld.args=-dynamiclib -m64 -arch x86_64 
-Wl,-dead_strip,-dead_strip_dylibs,-install_name,libJNativeHook.jnilib.1.1,-comp
atibility_version,1.1,-current_version,1.1.0,-s
native.ld.args2=-framework ApplicationServices -framework IOKit -framework 
Carbon -o

Original comment by pepijndevos on 27 Aug 2012 at 3:44

GoogleCodeExporter commented 9 years ago
You should not need to build it your self.  It looks like Apple has botched 
something with their new JDK bundle.  I don't own a Mac that is new enough to 
run 10.7 so I am looking into other ways of testing this.

Original comment by a...@1stleg.com on 27 Aug 2012 at 6:50

GoogleCodeExporter commented 9 years ago
Alright, compiling requires one more include path at the end of native.cc.args: 
-I/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/darwin  

It still doesn't run after it compiles.  That problem seems to be caused by the 
Class objects getResourceAsStream method returning null on OS X.  See:  
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStrea
m(java.lang.String) 

That method appears to function correctly on Windows, Linux and Solaris using 
the binaries provided by Oracle.  I am about 5 minutes away from calling this a 
JRE bug on OS X probably due to a botched custom class loader for the platform. 
 I will dig around a bit more and see if I can find a solution but I believe 
that a bug report to oracle will be required.  You should be able to work 
around the problem by specifying the java.library.path manually (Ex: java 
-Djava.library.path=/path/to/dylib/ -jar JNativeHook.jar)

Original comment by a...@1stleg.com on 27 Aug 2012 at 11:03

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Scratch the bug, I found the issue.  It is looking for the wrong filename.  For 
some reason Java 7 returns .dylib for System.mapLibraryName() instead of jnilib.

Original comment by a...@1stleg.com on 27 Aug 2012 at 11:49

GoogleCodeExporter commented 9 years ago
Fixed in revision 598.

Original comment by a...@1stleg.com on 28 Aug 2012 at 6:07

GoogleCodeExporter commented 9 years ago
Thanks for the super quick fix.

Now, unless there will be a new RC soon, I will need to build it from source 
anyway.

What does the process look like to generate a jar with Mac, Linux and Windows 
natives?

p.s. this is what we're building: https://github.com/davidleibovic/keymusix

Original comment by pepijndevos on 28 Aug 2012 at 11:40

GoogleCodeExporter commented 9 years ago
Np. Generating cross compiled binaries is a pain.  There is a binary attached 
to bug #19 that covers up the the current trunk.  There maybe some problems 
with that binary but I will update it as that bug progresses.  I am trying to 
resolve bug #18 before the final 1.1 but if that takes to much longer it may 
need to wait.  If you need a custom build just let me know.  It only takes a 
few seconds to run it though the cross compiler.

Original comment by a...@1stleg.com on 28 Aug 2012 at 3:32