Java 在哪里可以找到 Mac OS 的 jni 标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20771803/
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
Where can I find the jni headers for Mac OS
提问by TwilightSun
I'm not asking where I can find it on my own computer, I'm asking where I can get it.
我不是问在我自己的电脑上哪里可以找到它,我是在问我在哪里可以得到它。
I've done my google homework, and I didn't find the headers in those paths. There wasn't even a Header folder in my /System/Library/Java/JavaVirtualMachines/... and stuff and I don't have a Developer folder under root.
我已经完成了我的谷歌作业,但我没有在这些路径中找到标题。我的 /System/Library/Java/JavaVirtualMachines/... 中甚至没有 Header 文件夹,而且我的根目录下没有 Developer 文件夹。
Now I'm pretty sure I don't have those headers installed, I checked the MacOS developer website but I only found some broken links.
现在我很确定我没有安装那些标头,我检查了 MacOS 开发者网站,但我只发现了一些损坏的链接。
Shouldn't OpenJDK or SunJDK provide the jni.h header for MacOS somewhere?
OpenJDK 或 SunJDK 不应该在某处为 MacOS 提供 jni.h 标头吗?
采纳答案by Alex Cohn
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
But this depends on your environment.
但这取决于您的环境。
回答by Alan Zhiliang Feng
On Mac OS X 10.8.5, I use "/System/Library/Frameworks/JavaVM.framework/Headers", like:
在 Mac OS X 10.8.5 上,我使用“/System/Library/Frameworks/JavaVM.framework/Headers”,例如:
HelloJNI.o : HelloJNI.c HelloJNI.h
gcc -I"/System/Library/Frameworks/JavaVM.framework/Headers" -fpic -c $< -o $@
BTW, I am using this version of Java:
顺便说一句,我正在使用这个版本的 Java:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
回答by sodino
- jdk8 download web url: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
download it and install.
下载并安装。
- check java version:
- 检查Java版本:
sodino:~ sodino$ java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
sodino:~ sodino$ java -version java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
3.find 'java' original path and ‘java_home':
3.找到'java'原始路径和'java_home':
sodino:~ sodino$ which java /usr/bin/java sodino:~ sodino$ ls -n /usr/bin/java lrwxr-xr-x 1 0 0 74 Sep 30 2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java sodino:~ sodino$/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
sodino:~ sodino$ which java /usr/bin/java sodino:~ sodino$ ls -n /usr/bin/java lrwxr-xr-x 1 0 0 74 Sep 30 2014 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java sodino:~ sodino$/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
get ‘include' folder and jni.h
now you will find a ‘include' folder with in ‘/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home', and open it ‘jni.h' will be found.
获取“包含”文件夹和 jni.h
现在你会在“/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home”中找到一个“include”文件夹,打开它会发现“jni.h”。
回答by Peter Hull
You can use the java_home
command to find the correct location. See the Oracle docs.
您可以使用该java_home
命令找到正确的位置。请参阅Oracle 文档。
So for example in your makefile you could have:
因此,例如在您的 makefile 中,您可以拥有:
JAVA_HOME:=`/usr/libexec/java_home`
CPPFLAGS:=-I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/darwin
Note that you also need to add $(JAVA_HOME)/include/darwin
to the include path so it can find jni_md.h
which is the machine-specific part and is included by jni.h
请注意,您还需要添加$(JAVA_HOME)/include/darwin
到包含路径中,以便它可以找到jni_md.h
哪个是特定于机器的部分并由jni.h