This problem has plagued me for a week now. I have installed rJAVA from R running on a Ubuntu server 14.04. I installed rJava package as source like this:
install.packages("rJava", type="source")
and I get:
DONE(rJava)
I have installed java-8-openjdk and when running java -version I get the correct version and this is the output:
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
However when I check the java version in R using either
sudo R CMD javareconf
or
library(rJava)
jinit()
.jcall("java/lang/System", "S", "getProperty", "java.runtime.version")
The java version is still set to 1.7:
Java interpreter : /usr/lib/jvm/default-java/jre/bin/java
Java version : 1.7.0_101
Java home path : /usr/lib/jvm/default-java
Java compiler : /usr/lib/jvm/default-java/bin/javac
Java headers gen.: /usr/lib/jvm/default-java/bin/javah
Java archive tool: /usr/lib/jvm/default-java/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/include
detected JNI linker flags : -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/default-java/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/default-java
Java library path: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server
JNI cpp flags : -I$(JAVA_HOME)/include
JNI linker flags : -L/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
Please let me know what I'm missing.
I had the same problem: java -version gave Java 8, but sudo R CMD javareconf gave Java 7.
Running sudo R CMD javareconf --help gives:
Environment variables that can be used to influence the detection:
JAVA path to a Java interpreter executable
By default first 'java' command found on the PATH
is taken (unless JAVA_HOME is also specified).
JAVA_HOME home of the Java environment. If not specified,
it will be detected automatically from the Java
interpreter.
The documentation tells us to do what Dirk suggested: ensure that the first java found on PATH is the one we want. That did not help in my case, even though JAVA_HOME was not set. Abdou's suggestion of setting JAVA_HOME in my .Rprofile dit not help either.
To solve the problem, I had to set root's JAVA_HOME to the one I wanted (because R CMD javareconf is run as sudo):
sudo -i
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
R CMD javareconf
exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With