14

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

tamasp
  • 171
  • 1
  • 1
  • 6

4 Answers4

16

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.

cdeterman
  • 19,630
  • 7
  • 76
  • 100
  • Still not working. See above for full details. Thanks.: 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 – tamasp Nov 07 '14 at 18:22
  • did the above, but still: 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’ Where do I export the CLASSPATH info to? – tamasp Nov 07 '14 at 19:38
  • Did you locate getsp? You are exporting an environmental variable. `export CLASSPATH=/usr/...` is run at the command line. – cdeterman Nov 07 '14 at 19:39
  • yes, I did locate it using: locate getsp.class showed, among others "/usr/share/R/java/getsp.class" and therefore I used "export CLASSPATH=/usr/share/R/java" – tamasp Nov 07 '14 at 19:42
  • One further thought with JAVA_HOME added above. – cdeterman Nov 07 '14 at 20:05
  • The problem remains unsolved: 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 – tamasp Nov 07 '14 at 20:43
  • A side thought, I noticed you mentioned you are using Rstudio. Have you been trying to install rJava in RStudio or on the commandline? RStudio would need to be restarted to recognize any changes to the environment. You could also try to set JAVA_HOME directly in R with `Sys.setenv(JAVA_HOME="/usr/share/...")`. If all else fails, you probably should submit to [rJava issues](https://github.com/s-u/rJava/issues) – cdeterman Nov 07 '14 at 21:03
3

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

tamasp
  • 171
  • 1
  • 1
  • 6
  • If you believe my answer is correct (i.e. setting JAVA_HOME), please accept it. Otherwise accept your own answer so others may know the problem is solved. – cdeterman Nov 10 '14 at 13:43
2

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.

Che
  • 21
  • 2
-1

This solution worked for me perfectly:

https://orajavasolutions.wordpress.com/2014/06/03/installing-and-loading-xlsx-package-in-r-with-ubuntu/
sunny
  • 1,887
  • 3
  • 29
  • 40
  • Please don't use link-only answers: the links die with time and then the answer is worthless. Rather, provide a succinct summary of the important and useful part of the link in your answer, along with the link. – Richard Jul 13 '16 at 07:11