0
votes

I am using Red Hat 5, and unable to install rJava Package

I ran the following command:

$ R CMD javareconf -e

I get the following error:-

trying to compile and link a JNI program detected JNI cpp flags :

detected JNI linker flags :

gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/local/include
-fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fpic -fPIC -c conftest.c -o conftest.o

conftest.c:1:17: fatal error: jni.h: No such file or directory

compilation terminated.

make: *** [conftest.o] Error 1

Unable to compile a JNI program


java -version is below:-

java version "1.8.0_91"

Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mod


JAVA_HOME = /usr/java/jdk1.8.0_91/jre

Can anyone please help me to compile JNI Program

2
removing the "jre" from JAVA_HOME should help. The include files are in JDK.user2543253
Try installing all packages related to java with below command yum install java-1.8* this helped in solving above error.Santosh Garole

2 Answers

0
votes

I had similar problem on Ubuntu. Identify where is the file you are missing

find / -name jni.h 2> /dev/null

probably it will be something like

/usr/lib/jvm/java-8-openjdk-amd64/include

you might also be missing jni_md.h, then run something like below, where the paths are corrected for the ones identified above.

R CMD javareconf JAVA_CPPFLAGS="-I/usr/lib/jvm/java-8-openjdk-amd64/include -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/"
0
votes

You need to use JDK instead of JRE. JDK contains libs and headers required for JNI compilation.

In general, you have to reconfigure R and make sure to point to proper Java installation.

Take a look here: http://www.owsiak.org/?p=3671 where you can find quite detailed explanation of all the steps you have to take in order to get R properly working with Java. Explanation was prepared for macOS, but it will work for Linux based systems as well - with little modifications.

Just to summarize:

  1. install JDK
  2. reconfigure R

    sudo R CMD javareconf \
    JAVA_HOME=${JAVA_HOME} \
    JAVA=${JAVA_HOME/bin/java \
    JAVAC=${JAVA_HOME}/bin/javac \
    JAVAH=${JAVA_HOME}/bin/javah \
    JAR=${JAVA_HOME}/bin/jar \
    JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/server \
    JAVA_CPPFLAGS="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux"
    
  3. start R and install packages that require Java