Java Linux 上的 JDK 1.8 缺少 JNI 包含文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24996017/
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-14 16:21:42  来源:igfitidea点击:

JDK 1.8 on Linux missing JNI include file

javalinuxjava-native-interfacejava-8header-files

提问by arash javan

I am trying to compile the following project:

我正在尝试编译以下项目:

https://github.com/entropia/libsocket-can-java

I always get this error message? Does anyone know how to fix it, is it possibly a bug in JDK 1.8.0.11 on Linux (x64 Debian Wheezy)?

我总是收到此错误消息?有谁知道如何修复它,它可能是 Linux (x64 Debian Wheezy) 上 JDK 1.8.0.11 中的错误吗?

In file included from jni/de_entropia_can_CanSocket.h:2:0,
             from jni/cansocket.cpp:23:
/opt/jdk1.8.0_11/include/jni.h:45:20: fatal error: jni_md.h: No such file or directory
#include "jni_md.h"
                ^

采纳答案by Salem

It seems so. #include "jni_md.h"would include the file in the same directory as jni.h, but it is placed in linuxfolder.

似乎是这样。#include "jni_md.h"会将文件包含在与 相同的目录中jni.h,但它放在linux文件夹中。

In previous JDK versions it seems that file and another were place in include/linuxfolder, but there are symlinks to both files in include.

在以前的 JDK 版本中,文件和另一个文件似乎都放在include/linux文件夹中,但是include.

So you can just create symlinks to both files:

所以你可以只为这两个文件创建符号链接:

$ sudo ln -s /opt/jdk1.8.0_11/include/linux/jni_md.h /opt/jdk1.8.0_11/include/jni_md.h
$ sudo ln -s /opt/jdk1.8.0_11/include/linux/jawt_md.h /opt/jdk1.8.0_11/include/jawt_md.h

Edit

编辑

As stated in the comments by Absurd-Mind and Mikkel, there is also the option to add that path to the makefile compiler options:

正如 Absurd-Mind 和 Mikkel 的评论中所述,还可以选择将该路径添加到 makefile 编译器选项中:

-I$(JAVA_HOME)/include/linux/

回答by teardrop

No, this is not a bug. The correct way to solve this issue is to provide -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linuxcompiler options. This way your build scripts remain portable.

不,这不是错误。解决这个问题的正确方法是提供-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux编译器选项。这样您的构建脚本就可以保持可移植性。

The OP is facing the problem on Linux, but if anybody is facing this problem on windows, please add following compiler options.

OP 在 Linux 上面临这个问题,但如果有人在 Windows 上面临这个问题,请添加以下编译器选项。

-I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32"where JAVA_HOME points to your JDK installation directory, usually 'C:\Program Files\Java\jdk1.{7|8}.{}_{xx}'

-I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32"其中 JAVA_HOME 指向你的 JDK 安装目录,通常是 'C:\Program Files\Java\jdk1.{7|8}.{}_{xx}'

回答by imriss

It is also possible that there are more than one JDKthat have been deployed, and the one that is linked to $JAVA_HOMEis not the correct one. You need to update $JAVA_HOMEto that that contains the jni_md.hfile.

也有可能JDK已经部署了不止一个,并且链接到的那个$JAVA_HOME不是正确的。您需要更新$JAVA_HOME到包含该jni_md.h文件的那个。