如何在 OS X Lion 上安装 Java 原生开发头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9704376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:27:05  来源:igfitidea点击:

How to install Java native development headers on OS X Lion

javajava-native-interfaceosx-lion

提问by Steve

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/.

我正在尝试构建一个 JNI 项目,但我似乎找不到 JNI 头文件(例如jni.h)。我已经从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/Headersor /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. Any suggestions?

我看到了其他 JDK 组件——例如/System/Library/Frameworks/JavaVM.framework/Commands/javah——但没有看到 JNI 头文件。有什么建议?



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 现在将 JDK 安装在 下/Library/Java/JavaVirtualMachines,而 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). To point Maven at the proper JDK, I added /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/binto 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:

但我仍然坚持我的实际目标,即为 LevelDB 构建 JNI 包装器(根据 github.com/fusesource/leveldbjni 上的说明)。为了将 Maven 指向正确的 JDK,我添加/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin到 PATH 的前面,并将 JAVA_HOME 设置为/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home. 经过一段时间后,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"? Some digging around led me to http://www.arm4.org/trac/browser/branches/architecture/m4/jni.m4which 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/.

我不能确定 Maven 正在寻找什么来识别“我们可以使用的 JDK”?一些挖掘使我到http://www.arm4.org/trac/browser/branches/architecture/m4/jni.m4似乎在几个地方寻找 jni.h 并尝试编译它,但我不不知道这个jni.m4是否与Maven有任何实际关系。我在 /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/ 中有 jni.h。

回答by technomage

You probably need to install the Java Documentation package to get the headers; for the last few releases they have not been included in the JDK package. After installation, they will show up in /System/Library/Frameworks/JavaVM.framework/Headers.

您可能需要安装 Java 文档包来获取标头;在最近的几个版本中,它们没有包含在 JDK 包中。安装后,它们将显示在 /System/Library/Frameworks/JavaVM.framework/Headers 中。

[edit] Apple used to bundle the JNI headers with the JDK doc package. This is no longer the case; the JNI headers shouldbe bundled with the Java developer package.

[编辑] Apple 过去常常将 JNI 头文件与 JDK doc 包捆绑在一起。这已不再是这种情况; JNI 标头与 Java 开发人员包捆绑在一起。

回答by PatchyFog

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.

我知道这是一个旧线程,但这是我今天(2014 年 3 月末)为获取最新信息所做的工作,以便我可以构建一些需要 Java 标头的 Ruby GEM。矫枉过正,但我​​认为涵盖了所有基础。

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

  2. Install it.

  3. See where Oracle put it:

    $/usr/libexec/java_home
    /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    
  4. 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
    
  5. Symlink to make a Headers directory in JavaVM.framewrk:

    $cd /System/Library/Frameworks/JavaVM.framework
    $sudo ln -nsf Versions/CurrentJDK/Home/include/ ./Headers
    
  1. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载 Java 8 JDK

  2. 安装它。

  3. 看看 Oracle 把它放在哪里:

    $/usr/libexec/java_home
    /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    
  4. 从那里到 Apple 过去放置它的位置的符号链接:

    $cd /System/Library/Frameworks/JavaVM.framework/Versions
    $sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents ./CurrentJDK
    
  5. 在 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_HOMEyet because I haven't needed it.

这对我来说是固定的。我还没有为定义JAVA_HOME而烦恼,因为我不需要它。