简体   繁体   English

如何在OS X Lion上安装Java本机开发标头

[英]How to install Java native development headers on OS X Lion

I'm trying to build a JNI project, but I can't seem to find the JNI headers (eg jni.h ). 我正在尝试构建一个JNI项目,但我似乎无法找到JNI头文件(例如jni.h )。 I've installed "Java for Mac OS X 10.7 Developer Package" from https://developer.apple.com/downloads/ . 我已经从https://developer.apple.com/downloads/安装了“Java for Mac OS X 10.7 Developer Package”。

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. 各种在线资源建议标题应该在/System/Library/Frameworks/JavaVM.framework/Headers/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/include等位置,但我可以'在任何地方找到它们 - 安装程序似乎没有创建它们。

I see other JDK components -- just for example, /System/Library/Frameworks/JavaVM.framework/Commands/javah -- but not the JNI headers. 我看到其他JDK组件 - 例如/System/Library/Frameworks/JavaVM.framework/Commands/javah - 但不是JNI标头。 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 . 更新:technomage指出Apple现在在/Library/Java/JavaVirtualMachines下安装JDK,JNI头文件位于/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). 但我仍然坚持我的实际目标,即为LevelDB构建JNI包装器(根据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 . 为了将Maven指向适当的JDK,我将/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin添加到我的PATH的前面,并将JAVA_HOME设置为/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home After chugging for a while, Maven now fails with: 经过一段时间的努力,Maven现在失败了:

[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"? 我无法确定Maven正在寻找什么来识别“我们可以使用的JDK”? 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. 一些挖掘引导我到http://www.arm4.org/trac/browser/branches/architecture/m4/jni.m4 ,似乎在几个地方寻找jni.h并尝试编译它,但我不喜欢不知道这个jni.m4是否与Maven有任何实际关系。 I do have jni.h in /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/. 我在/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/中有jni.h。

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. 我知道这是一个旧线程,但这是我今天所做的事情(3/14后期)所以我可以构建一些需要Java Headers的Ruby GEM。 Overkill, but covers all the bases, I think. 我认为,矫枉过正,但涵盖了所有基础。

  1. Download the Java 8 JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载Java 8 JDK

  2. Install it. 安装它。

  3. See where Oracle put it: 看看Oracle把它放在哪里:

     $/usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home 
  4. Symlink from there to where Apple used to put it: 符号链接从那里到Apple过去的地方:

     $cd /System/Library/Frameworks/JavaVM.framework/Versions $sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents ./CurrentJDK 
  5. Symlink to make a Headers directory in JavaVM.framewrk: 用于在JavaVM.framewrk中创建Headers目录的符号链接:

     $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. 我还没有为定义JAVA_HOME而烦恼,因为我不需要它。

You probably need to install the Java Documentation package to get the headers; 您可能需要安装Java Documentation包来获取标头; for the last few releases they have not been included in the JDK package. 对于最后几个版本,它们尚未包含在JDK包中。 After installation, they will show up in /System/Library/Frameworks/JavaVM.framework/Headers. 安装后,它们将显示在/System/Library/Frameworks/JavaVM.framework/Headers中。

[edit] Apple used to bundle the JNI headers with the JDK doc package. [edit] Apple过去常常将JNI标头与JDK doc包捆绑在一起。 This is no longer the case; 这已不再是这种情况; the JNI headers should be bundled with the Java developer package. JNI头文件与Java开发人员包捆绑在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM