R CMD javareconf does not find jni.h

I am trying to install rJava in a Debian-based Docker container (Jesse) with Anaconda.

Like the root I made

$ 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 seem to javareconffind it. And, if I look at all the variables that I could set using javareconf, for example, JAVA_HOME, I will not see the ability to set the JNI cpp flags, which would require proper inclusion.

I have seen various posts on the Internet on this issue, but have not found a solution.

+13
source share
7 answers

R looks to another place:

detected JNI cpp flags    : -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux

I had a similar problem, but after installing jdk everything is fine:

sudo apt-get install openjdk-8-jdk
+14

. , Java. , Java ​​.

update-alternatives: using /usr/lib/jvm/java-9-openjdk-amd64/bin/jar to provide /usr/bin/jar (jar) in auto mode

JAVA_HOME javareconf .

sudo R CMD javareconf JAVA_HOME=/usr/lib/jvm/java-9-openjdk-amd64/bin/jar

,

+7

, 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}
+6

Java 11 Ubuntu 18.04, jdk-11.0.1, : https://websiteforstudents.com/how-to-install-oracle-java-jdk-11-on-ubuntu-18-04 -16-04-18-10/

JAVA_HOME javaconf, @Spanska Forteva

sudo nano /usr/lib/R/etc/javaconfIn javaconf 

, 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~}

JAVA_HOME jdk:

: ${JAVA_HOME=/usr/lib/jvm/jdk-11.0.1}

CMD jni.h:

sudo R CMD javareconf /usr/lib/jvm/jdk-11.0.1/include/jni.h

, , , .

+1

- . ( : https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html):

  • JDK (jdk1.8.0_201) /usr/java/
  • JRE (jre1.8.0_201) /usr/java/( , , )
  • Ubuntu Java

:

$ 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

$ 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

Java

sudo update-alternatives --config java

Java.

 sudo R CMD javareconf JAVA_HOME=/usr/java/jdk1.8.0_201/bin/

java jdk . , , rJava Rstudio, glmulti.

+1

R CMD javareconf

su, sudo .

+1

, , .

:

(1)

sudo apt update -y

(2) , JRE JDK 8

sudo apt install -y openjdk-8-jdk openjdk-8-jre

(3) , , R java JDK 8

sudo R CMD javareconf JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/

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

jni.h?, / .

+1

Source: https://habr.com/ru/post/1671279/


All Articles