I'm trying to install rJava in a docker container based on debian (jessie) with Anaconda.
As root, I did
$ 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:
# 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.
I've seen various posts around the Internet of this problem, but no solutions.
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):
For this I ran:
followed by
Then I could finally see my java in the alternatives in
where I selected the newly installed java. Then I ran
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.
Had the same issue. Fixed by specifying the path to the Java folder. Briefly, after installing Java you may get a line like this.
I specified that path as JAVA_HOME argument when calling javareconf, as follows.
Hope this is useful
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/
I then changed JAVA_HOME in javaconf, just like @Spanska Forteva
I found that the path to an old version of java was still specified.
I changed the path to JAVA_HOME to my newly installed jdk:
Then ran the CMD with the path to jni.h specified:
The last bit might not be needed, it should be able to look in that folder anyway, but that is what I did.
I solved the problem by editing the java-config file
R is looking at different location:
I experienced similar problem, but everything is fine after installing jdk: