In Ubuntu 12.04, I have jdk7 from sun/oracle installed. When locate jni.h, it prints multiple locations
/usr/lib/jvm/java-6-openjdk-amd64/include/jni.h
/usr/lib/jvm/jdk1.7.0_07/include/jni.h
...
In the header file generated by JDK, there is include <jni.h>, and currently it complains
fatal error: jni.h: No such file or directory.
In my Makefile, there is no specification of locations where jni.h is. And I am asking if possible to configure certain system parameter to make path of jni.h (say, /usr/lib/jvm/jdk1.7.0_07/include/jni.h) to be known when being compiled.
You have to tell your compiler where is the include directory. Something like this:
gcc -I/usr/lib/jvm/jdk1.7.0_07/include
But it depends on your makefile.
It needs both jni.h and jni_md.h files, Try this
gcc -I/usr/lib/jvm/jdk1.7.0_07/include \
-I/usr/lib/jvm/jdk1.7.0_07/include/linux filename.c
This will include both the broad JNI files and the ones necessary for linux
Installing the OpenJDK Development Kit (JDK) should fix your problem.
sudo apt-get install openjdk-X-jdk
This should make you able to compile without problems.
I usually define my JAVA_HOME variable like so:
export JAVA_HOME=/usr/lib/jvm/java/
Therein are the necessary include files. I sometimes add the below to my .barshrc when I compile a lot of things that need it.
Use the following code:
make -I/usr/lib/jvm/jdk*/include
where jdk* is the directory name of your jdk installation (e.g. jdk1.7.0).
And there wouldn't be a system-wide solution since the directory name would be different with different builds of JDK downloaded and installed. If you desire an automated solution, please include all commands in a single script and run the said script in Terminal.
Setting JAVA_INCLUDE_DIR to where jni.h is located should solve your problem (setting CPPFLAGS did not work for me)
Assuming it is /usr/lib64/java/include;
export JAVA_INCLUDE_DIR=/usr/lib64/java/include
For me it was a simple matter of being sure to include the JDK installation (I'd only had the JRE). My R CMD javareconf output was looking like:
Java interpreter : /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Java version : 1.8.0_191
Java home path : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java compiler : not present
Java headers gen.:
Java archive tool:
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
/usr/lib/R/etc/Makeconf:159: recipe for target 'conftest.o' failed
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
And indeed there was no include file in my $JAVA_HOME. Very simple remedy:
sudo apt-get install openjdk-8-jre openjdk-8-jdk
(note that this is specifically intended to install the openJDK and not the one from Oracle)
Afterwards all is well:
Java interpreter : /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Java version : 1.8.0_191
Java home path : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java compiler : /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-8-openjdk-amd64/jre/../bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include/linux -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
Above answers give you a hardcoded path solution. This is bad on so many levels (java version change, OS change, etc).
Cleaner solution is to add:
JAVA_HOME = $(shell dirname $$(readlink -f $$(which java))|sed 's^jre/bin^^')
near the top of your makefile, then add:
-I$(JAVA_HOME)/include
To your include flags.
I am posting this because I ran into the same problem and spent too much time googling for wrong answers (I am building an app on multiple platforms so the build environment needs to be transportable).
None of the posted solutions worked for me.
I had to vi into my Makefile and edit the path so that the path to the include folder and the OS subsystem (in my case, -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux) was correct. This allowed me to run make and make install without issues.
In case you are on Ubuntu:
#X means 6,7,8...
apt install openjdk-X-jdk
I don't know if this applies in this case, but sometimes the file got deleted for unknown reasons, copying it again into the respective folder should resolve the problem.
Related
I am trying to run rJava in RStudio but without success:
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rJava/libs/rJava.so
Reason: image not found
Using the common solution for rJava issues, 'sudo R CMD javareconf' doesn't work and gives me this ouput:
Java interpreter : /usr/bin/java
Java version : 11.0.6
Java home path : /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/include/darwin -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c conftest.c -o conftest.o
clang-7: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
In file included from conftest.c:1:
/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/include/jni.h:39:10: fatal error:
'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.
Did anyone come across this error before and knows how to tackle it?
I had a problem like this with a coworker recently after they upgraded to Catalina. My solution was to install the offending version of JDK again. It looks like your system has confusion between 11.0.6 and 11.0.1.
Go to this page:
https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase11-5116896.html
Download and install 11.0.1
sudo R CMD javareconf
sudo Rstudio # elevate privs
install.packages("rJava")
If that doesn't work, try again from step 2, but with 11.0.6 from https://www.oracle.com/technetwork/java/javase/overview/index.html
What did the trick in the end was to show Rstudio where to look as identified by user Rmadillo here:
github.com/rstudio/rstudio/issues/2254
Just run this each time before using the rJava package.
I have the very common problem that rJava does not install correctly on Ubuntu.
This problem has been dsicussed in multiple places here, here, here, to name a few.
The basic problem is that on installing the rJava package, the following error message is produced
configure: error: Unable to run a simple JNI program. Make sure you have configured R with Java support (see R documentation) and check config.log for failure reason.
Warning in system(cmd) : error in running command
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/jonno/R/x86_64-pc-linux-gnu-library/3.6/rJava’
There are various closely related solutions to this problem. Most of them use sudo R CMD javareconf to configure Java for R (also a -e variant). Some suggest setting the JAVA_HOME path in the environment variables (others say not to). Others suggest uninstalling and re-installing R whilst others suggest installing rJava from cran. There are several who reccomend update alternatives. There are other variants of these solutions.
I have tried combinations of all of the above, and have got nowhere, so am clearly doing something wrong.
entering echo $JAVA_HOME returns
/usr/lib/jvm/java-11-openjdk-amd64
my etc/environment looks like this
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/$
MKL_THREADING_LAYER=GNU
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
When I run R CMD javaconf, it looks like this
Java interpreter : /usr/lib/jvm/java-11-openjdk-amd64/java
Java version : 11.0.4
Java home path : /usr/lib/jvm/java-11-openjdk-amd64
Java compiler : /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/lib/jvm/java-11-openjdk-amd64/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -fpic -g -O2 -fdebug-prefix-map=/build/r-base-uuRxut/r-base-3.6.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -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-11-openjdk-amd64/lib/server -ljvm -L/usr/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-11-openjdk-amd64
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
What am I doing wrong and how do I get rJava to install properly?
EDIT:
having managed to successfully install rJava using sudo apt-get install r-cran-rjava I know get the following error
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
I've investigated with the original poster (we work at the same place) and the problem is that in OpenJDK11 they moved around some of the .so files that the JVM lives in, specifically libjvm.so which in the Ubuntu package is now in /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server/.
This means that even if you install the Ubuntu package for rJava with apt install r-cran-rjava it fails when you try to library(rJava).
The solution is to add /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server/ to your $LD_LIBRARY_PATH by adding:
export LD_LIBRARY_PATH=/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server:$LD_LIBRARY_PATH
to the end of your ~/.bashrc and starting a new shell (or source ~/.bashrc).
This is something we had to fix for our central installs of OpenJDK e.g. here: https://github.com/UCL-RITS/rcps-buildscripts/blob/master/adoptopenjdk-11.0.3_install.sh#L46
If you want to make this work with Rstudio launched from Gnome, you need to add that directory to ldconfig.
As root (or with sudo) create a file in /etc/ld.so.conf.d/ which you should call something with a .conf extension e.g. java.conf which contains the line:
/usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server
And then as root run
ldconfig -v
This should add the directory to the locations that executables launched through GNOME search for. This particular part of the problem (GNOME ignoring settings in bashrc) has been a problem in Ubuntu since at least 9.04 (https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/366728/).
I am trying to install rJava for my R enviroment.
I have tried this
$sudo locate libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
$sudo R CMD javareconf
Java interpreter : /usr/lib/jvm/default-java/jre/bin/java
Java version : 1.7.0_79
Java home path : /usr/lib/jvm/default-java
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L/usr/lib -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -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
conftest.c:1:17: fatal error: jni.h: No such file or directory
#include <jni.h>
^
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/default-java
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
In R side its showing this error
install.packages("rJava")
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
I believe this is the cause of the problem I some how installed two java environments and this is interfering with my rjava installation. How can i solve this.
I was trying to install the xlsx package, unfortunately, there is an issue with Java, which I am unable to solve.
Please find below the output produced when trying to install the package xlsx.
Here's the output:
R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> install.packages("xlsx")
Installing package into ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
also installing the dependencies ‘rJava’, ‘xlsxjars’
trying URL 'contrib/rJava_0.9-6.tar.gz'
Content type 'application/x-gzip' length 567515 bytes (554 Kb)
opened URL
==================================================
downloaded 554 Kb
trying URL 'contrib/xlsxjars_0.6.1.tar.gz'
Content type 'application/x-gzip' length 9477071 bytes (9.0 Mb)
opened URL
==================================================
downloaded 9.0 Mb
trying URL 'contrib/xlsx_0.5.7.tar.gz'
Content type 'application/x-gzip' length 312839 bytes (305 Kb)
opened URL
==================================================
downloaded 305 Kb
* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -m64 -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -m64 -std=gnu99 accepts -g... yes
checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc -m64 -std=gnu99 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/bin/java'
archiver : '/bin/jar'
compiler : '/bin/javac'
header prep.: '/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works...
Error: Could not find or load main class getsp
no
configure: error: Java interpreter '/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
ERROR: dependency ‘rJava’ is not available for package ‘xlsxjars’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/xlsxjars’
Warning in install.packages :
installation of package ‘xlsxjars’ had non-zero exit status
ERROR: dependencies ‘rJava’, ‘xlsxjars’ are not available for package ‘xlsx’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/xlsx’
Warning in install.packages :
installation of package ‘xlsx’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmpj1UG8a/downloaded_packages’
Java is installed:
java -version gives the following output:
java version "1.7.0_71"
OpenJDK Runtime Environment (fedora-2.5.3.0.fc20-x86_64 u71-b14)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
"sudo R CMD javareconf" leads to:
Java interpreter : /bin/java
Java version : 1.7.0_71
Java home path : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre
Java compiler : /bin/javac
Java headers gen.: /bin/javah
Java archive tool: /bin/jar
trying to compile and link a JNI progam
detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c conftest.c -o conftest.o
gcc -m64 -std=gnu99 -shared -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm -L/usr/lib64/R/lib -lR
JAVA_HOME : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib64/R
Done.
Nonetheless, install.packages('rJava') leads to:
checking Java support in R... present:
interpreter : '/bin/java'
archiver : '/bin/jar'
compiler : '/bin/javac'
header prep.: '/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71-2.5.3.0.fc20.x86_64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works...
Error: Could not find or load main class getsp
no
configure: error: Java interpreter '/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/tamaspavlicek/R/x86_64-redhat-linux-gnu-library/3.1/rJava’
Warning in install.packages :
installation of package ‘rJava’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmpnl17m7/downloaded_packages’
I have no idea how to fix this java problem. I work with RStudio and Fedora.
Your help is much appreciated.
Thanks
Tamas
If you have Java installed, try resetting R's java configuration from the commandline
sudo R CMD javareconf
Then try again to install just rJava (you might restart RStudio first)
install.packages('rJava')
If this still didn't solve your problem, the error shows that R could not load getsp.:
checking whether Java run-time works...
Error: Could not find or load main class getsp
First verify that getsp is accessible.
locate getsp
The output may contain several items but you should find something like this:
/usr/share/R/share/java/getsp.class
Then we want this to be accessible so export it so R can find it:
export CLASSPATH=/usr/share/R/share/java
In the same window, start another R session and try installing rJava again.
Another thing to rest would be JAVA_HOME and rerun the javareconf
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.71.x86_64/jre
export PATH=$PATH:$JAVA_HOME/bin
sudo R CMD javareconf
It is also recommended to unset CLASSPATH in the rJava issues as it may cause other issues down the line. You probably should do this before trying to change JAVA_HOME and reset again if this still doesn't solve the problem.
EDIT
Given that this question has remained 'unanswered' for quite some time I thought I should also add my recommendation to just use the readxl package instead which does not use Java. It installs much easier and is part of the tidyverse. Just a general recommendation for those trying to work with excel files.
Okay, I finally managed it by adding "JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25.x86_64/jre/" to .bashrc in my home folder.
Thank you for your help, cdeterman.
Best Tamas
It is the problem of Java. I think that you have not installed Java on your system. Check if Java already installed:
java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
sudo apt-get install default-jre
sudo apt-get install default-jdk
Then try to reinstall the package.
This solution worked for me perfectly:
https://orajavasolutions.wordpress.com/2014/06/03/installing-and-loading-xlsx-package-in-r-with-ubuntu/
I am not able to call rJava package in R 3.0. I got the following message
Error: package ‘rJava’ was built before R 3.0.0: please re-install it
I am getting error when I tried to re-install rJava package. I have provided the output of R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_21
Java home path : /usr/lib/jvm/java-7-openjdk-i386/jre
Java compiler : /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/jar
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 -O2 -pipe -g -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 library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I am using Ubuntu 13.04. I also tried apt-get install r-cran-rjava which is not helping to solve the issue. Regarding jni.h there were some solution here. But, not sure how can I use the solution here.
I ran into the exact same issue. My solution was to install the openjdk-7-* via
sudo apt-get install openjdk-7-*
Followed that with
sudo R CMD javareconf
and I was then able to install rJava in R via install.packages("rJava").
While perhaps not the most elegant solution it appears to have solved my problems with getting rJava to work.
For those getting the error:
error: unable to load shared object '/some/dir/rJava/libs/rJava.so': libjvm.so:
cannot open shared object file: No such file or directory
I solved the error locating the library in the system and linking them to /usr/lib:
$sudo updatedb
$locate libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Installing rJava from the distribution packages as proposed in this askUbuntu answer also works:
sudo apt-get install r-cran-rjava
NOTE: tried from a Debian system.
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 following output.