17

I want to install rJava but it doesnt work. When I am typing R CMD javareconf in the console I get the following error:

trying to compile and link a JNI progam
detected JNI cpp flags    :
detected JNI linker flags :
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -O3 -pipe  -g 
-c conftest.c -o conftest.o
conftest.c:1:17: error: jni.h: No such file or directory
conftest.c: In function 'main':
conftest.c:4: warning: implicit declaration of function 'JNI_CreateJavaVM'
make: *** [conftest.o] Error 1
Unable to compile a JNI program


Java library path:
JNI cpp flags    :
JNI linker flags :
Updating Java configuration in /usr/lib64/R
Done.

Any ideas how to fix it?

user2523848
  • 335
  • 2
  • 6
  • 14

3 Answers3

9

I know this is closed but I'm adding my solution for completeness. In effect I had the same problem and all was correctly installed. I had also run the

sudo R CMD javareconf

for system wide setting. What I needed was for it to work for my user. And in this case you should run

R CMD javareconf -e

without sudo and with appended -e.

Worked for me. :)

Dr. Mike
  • 2,451
  • 4
  • 24
  • 36
6

The jni.h file is part of JDK installation. You probably don't have Java JDK installed correctly. Download Oracle Java from here, or use your package manager.

If you have Java JDK already installed, set JAVA_HOME environment variable to point to the JDK directory.

Loša
  • 2,621
  • 2
  • 14
  • 19
  • I am working on a server over ssh with debian 6. Actually JDK ist installed correctly. I did a sudo apt-get install openjdk-6-jdk. Unfortunetaly sudo apt-get install ioenjdk-7-jdk does not work on debian 6 – user2523848 Jul 10 '13 at 12:37
  • 2
    Doesn't Debian have an rJava package that you could use? Try `apt-get install r-cran-rjava`. – Loša Jul 10 '13 at 12:41
  • Yes, It has but it is unfortunately the old version, which does not work with RHive: package 'rJava' 0.8-4 was found, but >= 0.9.0 is required for by 'RHive' – user2523848 Jul 10 '13 at 12:46
  • Do you have JDK directory in your PATH environment variable? – Loša Jul 10 '13 at 12:49
  • echo $PATH only returns: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. So I guess no :) – user2523848 Jul 10 '13 at 12:56
  • Try to find the `jni.h` file and add the directory that contains it to your PATH. That should help. – Loša Jul 10 '13 at 13:02
  • Please check http://stackoverflow.com/a/3311983/2541416. You may need to set JAVA_HOME as well. – Loša Jul 10 '13 at 17:58
  • hey, this really worked! Thank you very much. I had to set my JAVA_HOME – user2523848 Jul 11 '13 at 13:30
  • Hi, how does one edit the path and java_home environment variable? – Alex Jun 23 '14 at 06:03
  • I am stuck in a similar problem [here](https://stackoverflow.com/questions/45131343/rjava-linker-error-licuuc-when-trying-to-install-on-macos-sierra-10-12-4) with licuuc library/linker error in installing rJava, any ideas for it? – hhh Jul 16 '17 at 21:25
0

I was also facing same error which was on RHEL8.1 & i resolved it as follows:

 yum --enablerepo=* install java-1.8* 

later i ran same command which was giving me error logs of R server.

 R CMD javareconf

which turns into the following output & succeed.

enter image description here

Santosh Garole
  • 1,419
  • 13
  • 23