Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R CMD javareconf not finding jni.h

Tags:

java

r

rjava

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.

like image 402
dfrankow Avatar asked Mar 02 '17 17:03

dfrankow


2 Answers

I'm not sure if an answer has been confirmed here, but I would point everyone to this article by Andrew Collier.

What he recommends:

(1) Updating all repositories

sudo apt update -y 

(2) Being sure JRE and JDK 8 are installed

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

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.

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.

like image 157
Please don't laugh at me Avatar answered Sep 22 '22 20:09

Please don't laugh at me


R is looking at different location:

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:

sudo apt-get install openjdk-8-jdk 
like image 29
sgu Avatar answered Sep 24 '22 20:09

sgu