I'm trying to build a JNI project, but I can't seem to find the JNI headers (e.g. jni.h
). I've installed "Java for Mac OS X 10.7 Developer Package" from https://developer.apple.com/downloads/.
Various online resources suggest the headers should be in locations such as /System/Library/Frameworks/JavaVM.framework/Headers
or /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include
, but I can't find them anywhere -- the installer doesn't seem to be creating them.
I see other JDK components -- just for example, /System/Library/Frameworks/JavaVM.framework/Commands/javah
-- but not the JNI headers. Any suggestions?
Update: technomage pointed out that Apple now installs the JDK under /Library/Java/JavaVirtualMachines
, and the JNI headers were at /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h
.
But I'm still stuck on my actual goal, which is to build the JNI wrappers for LevelDB (per instructions at github.com/fusesource/leveldbjni). To point Maven at the proper JDK, I added /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin
to the front of my PATH, and set JAVA_HOME to /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
. After chugging for a while, Maven now fails with:
[INFO] --- maven-hawtjni-plugin:1.5:build (default) @ leveldbjni-osx ---
[INFO] Extracting /Users/steve/leveldb/leveldbjni/leveldbjni/target/leveldbjni-99-master-SNAPSHOT-native-src.zip to /Users/steve/leveldb/leveldbjni/leveldbjni-osx/target/native-build-extracted
[INFO] executing: /bin/sh -c ./configure --disable-ccache --prefix=/Users/steve/leveldb/leveldbjni/leveldbjni-osx/target/native-build/target --with-leveldb=/Users/steve/leveldb/leveldb --with-snappy=/Users/steve/leveldb/snappy-1.0.3 --with-universal --with-leveldb=/Users/steve/leveldb/leveldb --with-snappy=/Users/steve/leveldb/snappy-1.0.3
...
[INFO] configure: JAVA_HOME was set, checking to see if it's a JDK we can use...
[INFO] checking if '/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home' is a JDK... no
[INFO] configure: javac was on your path, checking to see if it's part of a JDK we can use...
[INFO] checking if '/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home' is a JDK... no
[INFO] configure: Taking a guess as to where your OS installs the JDK by default...
[INFO] checking if '/System/Library/Frameworks/JavaVM.framework' is a JDK... no
[INFO] configure: error: JDK not found. Please use the --with-jni-jdk option
I can't tell for sure what Maven is looking at to identify "a JDK we can use"? Some digging around led me to http://www.arm4.org/trac/browser/branches/architecture/m4/jni.m4 which appears to look for jni.h in a few places and try to compile it, but I don't know whether this jni.m4 has any actual relationship Maven. I do have jni.h in /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/.
In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.
The message “Unable to load Java Runtime Environment” means that the Mac computer cannot load JRE, either because it is out of date or (more usually) because it has not yet been downloaded and installed. It can also happen after the computer OS X has been updated, e.g. to 10.14 Mojave from 10.13 Maverick.
I know this is an old thread, but here is what I did to get current today (Late 3/14) so I could build some Ruby GEM that needed the Java Headers. Overkill, but covers all the bases, I think.
Download the Java 8 JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Install it.
See where Oracle put it:
$/usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
Symlink from there to where Apple used to put it:
$cd /System/Library/Frameworks/JavaVM.framework/Versions
$sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents ./CurrentJDK
Symlink to make a Headers directory in JavaVM.framewrk:
$cd /System/Library/Frameworks/JavaVM.framework
$sudo ln -nsf Versions/CurrentJDK/Home/include/ ./Headers
This fixed things for me. I haven't bothered with defining JAVA_HOME
yet because I haven't needed it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With