java R CMD javareconf 没有找到 jni.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42562160/
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
R CMD javareconf not finding jni.h
提问by dfrankow
I'm trying to install rJava in a docker container based on debian (jessie) with Anaconda.
我正在尝试使用 Anaconda 在基于 debian (jessie) 的 docker 容器中安装 rJava。
As root, I did
作为 root,我做了
$ apt-get update && apt-get install -y --no-install-recommends \
default-jdk default-jre libicu-dev
Then
然后
$ R CMD javareconf
Java interpreter : /usr/lib/jvm/jdk1.8.0_121/jre/bin/java
Java version : 1.8.0_121
Java home path : /usr/lib/jvm/jdk1.8.0_121
Java compiler : /usr/lib/jvm/jdk1.8.0_121/bin/javac
Java headers gen.: /usr/lib/jvm/jdk1.8.0_121/bin/javah
Java archive tool: /usr/lib/jvm/jdk1.8.0_121/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux
detected JNI linker flags : -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/opt/conda/lib/R/include -DNDEBUG -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -I/opt/conda/include -fpic -I/opt/conda/include -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
#include <jni.h>
^
compilation terminated.
/opt/conda/lib/R/etc/Makeconf:133: recipe for target 'conftest.o' failed
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/jdk1.8.0_121
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /opt/conda/lib/R
Done.
But jni.h is right in the JDK:
但是 jni.h 在 JDK 中是正确的:
# find /usr/lib/jvm/jdk1.8.0_121/ -name jni.h
/usr/lib/jvm/jdk1.8.0_121/include/jni.h
It just doesn't look like javareconf
is finding it. And, if I look at all the variables I could set with javareconf, like JAVA_HOME, I don't see the ability to set JNI cpp flags, which would need the right includes.
它只是看起来不像javareconf
是找到它。而且,如果我查看可以使用 javareconf 设置的所有变量,例如 JAVA_HOME,我看不到设置 JNI cpp 标志的能力,这需要正确的包含。
I've seen variouspostsaround the Internet of this problem, but no solutions.
回答by sgu
R is looking at different location:
R 正在查看不同的位置:
detected JNI cpp flags : -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux
I experienced similar problem, but everything is fine after installing jdk:
我遇到了类似的问题,但安装 jdk 后一切正常:
sudo apt-get install openjdk-8-jdk
回答by Damiano Fantini
Had the same issue. Fixed by specifying the path to the Java folder. Briefly, after installing Java you may get a line like this.
有同样的问题。通过指定 Java 文件夹的路径来修复。简而言之,在安装 Java 之后,您可能会看到这样的一行。
update-alternatives: using /usr/lib/jvm/java-9-openjdk-amd64/bin/jar to provide /usr/bin/jar (jar) in auto mode
I specified that path as JAVA_HOME argument when calling javareconf, as follows.
我在调用 javareconf 时将该路径指定为 JAVA_HOME 参数,如下所示。
sudo R CMD javareconf JAVA_HOME=/usr/lib/jvm/java-9-openjdk-amd64/bin/jar
Hope this is useful
希望这是有用的
回答by Spaska Forteva
I solved the problem by editing the java-config file
我通过编辑 java-config 文件解决了这个问题
sudo nano /usr/lib/R/etc/javaconf
set the correct JAVA_HOME in this row:
: ${JAVA_HOME=/usr/local/java/jdk-9.0.1}
回答by Please don't laugh at me
I'm not sure if an answer has been confirmed here, but I would point everyone to this articleby Andrew Collier.
我不确定这里是否已经确认了答案,但我会向所有人指出Andrew Collier 的这篇文章。
What he recommends:
他的建议是:
(1) Updating all repositories
(1) 更新所有仓库
sudo apt update -y
(2) Being sure JRE and JDK 8 are installed
(2) 确保安装了 JRE 和 JDK 8
sudo apt install -y openjdk-8-jdk openjdk-8-jre
(3) Then, as many users have said already, pointing R to java with an explicit path to JDK 8
(3) 然后,正如许多用户已经说过的那样,将 R 指向 java 并带有指向 JDK 8 的显式路径
sudo R CMD javareconf JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
The specific Java package does not matter too much as long as it has all the necessary compiled contents within the /include directory.
特定的Java 包没有太大关系,只要它在/include 目录中包含所有必需的编译内容即可。
user@laptop:~$ ls /usr/lib/jvm/java-8-openjdk-amd64/include/
classfile_constants.h jdwpTransport.h jvmticmlr.h linux
jawt.h jni.h jvmti.h
For more on this, I would recommend how to make jni.h be found?for going about locating/compiling this directory correctly.
有关这方面的更多信息,我建议如何找到 jni.h?用于正确定位/编译此目录。
回答by chilifan
I already had Java 11 on ubuntu 18.04 but had to install jdk-11.0.1 following this guide: https://websiteforstudents.com/how-to-install-oracle-java-jdk-11-on-ubuntu-18-04-16-04-18-10/
我已经在 ubuntu 18.04 上安装了 Java 11,但必须按照本指南安装 jdk-11.0.1:https: //websiteforstudents.com/how-to-install-oracle-java-jdk-11-on-ubuntu-18-04 -16-04-18-10/
I then changed JAVA_HOME in javaconf, just like @Spanska Forteva
然后我在javaconf中更改了JAVA_HOME,就像@Spanska Forteva
sudo nano /usr/lib/R/etc/javaconfIn javaconf
I found that the path to an old version of java was still specified.
我发现仍然指定了旧版本java的路径。
## Versions from settings when configure was run
: ${JAVA_HOME=/usr/lib/jvm/default-java}
: ${JAVA_CPPFLAGS=~autodetect~}
: ${JAVA_LD_LIBRARY_PATH=~autodetect~}
: ${JAVA_LIBS=~autodetect~}
I changed the path to JAVA_HOME to my newly installed jdk:
我将JAVA_HOME的路径改为我新安装的jdk:
: ${JAVA_HOME=/usr/lib/jvm/jdk-11.0.1}
Then ran the CMD with the path to jni.h specified:
然后使用指定的 jni.h 路径运行 CMD:
sudo R CMD javareconf /usr/lib/jvm/jdk-11.0.1/include/jni.h
The last bit might not be needed, it should be able to look in that folder anyway, but that is what I did.
可能不需要最后一点,无论如何它应该能够查看该文件夹,但这就是我所做的。
回答by Obnebion
Had the same problem and could finally fix it. After a lot of searching, this worked for me (I basically followed the guide here: https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html):
遇到了同样的问题,终于可以解决了。经过大量搜索,这对我有用(我基本上遵循了这里的指南:https: //www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html):
- downloading and unpacking the JDK (jdk1.8.0_201) to /usr/java/
- downloading and unpacking the JRE (jre1.8.0_201) to /usr/java/ (not sure if I needed this step but I did it in previous attempts to solve this problem)
- Informing Ubuntu of the new java using appropriate versions
- 下载并解压 JDK (jdk1.8.0_201) 到 /usr/java/
- 将 JRE (jre1.8.0_201) 下载并解压到 /usr/java/(不确定是否需要此步骤,但我在之前尝试解决此问题时已这样做)
- 使用适当的版本通知 Ubuntu 新的 java
For this I ran:
为此,我跑了:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_201/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_201/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_201/bin/javaws" 1
followed by
其次是
$ sudo update-alternatives --set java /usr/java/jdk1.8.0_201/bin/java
$ sudo update-alternatives --set javac /usr/java/jdk1.8.0_201/bin/javac
$ sudo update-alternatives --set javaws /usr/java/jdk1.8.0_201/bin/javaws
Then I could finally see my java in the alternatives in
然后我终于可以在替代品中看到我的 java
sudo update-alternatives --config java
where I selected the newly installed java. Then I ran
我在这里选择了新安装的java。然后我跑了
sudo R CMD javareconf JAVA_HOME=/usr/java/jdk1.8.0_201/bin/
in which I specified again my java jdk path explicitely. After this finished successfully I was able to install rJava in Rstudio which I needed to install glmulti.
在其中我再次明确指定了我的 java jdk 路径。成功完成后,我能够在 Rstudio 中安装 rJava,我需要安装 glmulti。
回答by Alexander B. Leichtle
In my case, I had to run
就我而言,我不得不跑
R CMD javareconf
as su
, just sudo
didn't work.
因为su
,只是sudo
没有用。