Search code examples
javareclipseubuntustatet

Not able to install rj package for Eclipse StatEt plugin


Because the Ubuntu upgrade to 18.04 destroyed my working Eclipse configuration, I reinstalled Eclipse (Photon Release 4.8.0) and tried to use again R with the StatET 3.6 plugin. As suggested here, I attempted to install the package rj-2.1 in an R term console via

install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-2.1")

and this started to install rj and rj.gd

Installing packages into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

but ends with an error message:

Warning message:
In install.packages(c("rj", "rj.gd"), repos = "http://download.walware.de/rj-2.1") :
  installation of package ‘rj’ had non-zero exit status

A closer look into the console output reveals this error message:

checking Java support in R... configure: error: cannot determine complete java config
    JAVA_HOME: /usr/lib/jvm/default-java
    JAVA     : /usr/lib/jvm/default-java/bin/java
    JAVAC    : /usr/lib/jvm/default-java/bin/javac
    JAVAH    : 
    JAVA_CPPFLAGS: -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux
    JAVA_LIBS: -L/usr/lib/jvm/default-java/lib/server -ljvm
    JAR      : /usr/lib/jvm/default-java/bin/jar
R is not configured with full Java support. Please make sure
an JDK is installed and 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 the package.
ERROR: configuration failed for package ‘rj’
* removing ‘/usr/local/lib/R/site-library/rj’
* restoring previous ‘/usr/local/lib/R/site-library/rj’

When I run the suggested command

sudo R CMD javareconf

in a terminal, the output suggests that it works as expected

Java interpreter : /usr/lib/jvm/default-java/bin/java
Java version     : 10.0.2
Java home path   : /usr/lib/jvm/default-java
Java compiler    : /usr/lib/jvm/default-java/bin/javac
Java headers gen.: 
Java archive tool: /usr/lib/jvm/default-java/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/default-java/include -I/usr/lib/jvm/default-java/include/linux     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -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/default-java/lib/server -ljvm -L/usr/lib/R/lib -lR


JAVA_HOME        : /usr/lib/jvm/default-java
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.

Nonetheless, the installation of rj-2.1 still produces afterwards the same error message. I had a look at /usr/local/lib/R/site-library and rj.gd is updated, but rj is still the previous version. And starting the R console produces the error message

eclipse.buildId=4.8.0.I20180611-0500
java.version=10.0.2
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_GB
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.java.product

de.walware.statet.r.console.ui

Launching the R Console was cancelled, because it seems starting the R engine failed.
Please make sure that R package 'rj' (2.1 or compatible) is installed and that the R library paths are set correctly for the R environment configuration 

Any idea, how to get rj installed?

P.S.: Seems to be a Java version problem. Ubuntu 18.04 has this version preinstalled:

openjdk 10.0.2 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.1)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.1, mixed mode)

Update:
Without knowingly having changed anything, the installation of rj and rj.gd from an Rterm console worked now. The files in /usr/local/lib/R/site-library are indeed updated and the Rterm console does not have any error messages.
Nonetheless, when creating and running an RJ console, the same error message appears

Launching the R Console was cancelled, because it seems starting the R engine failed. 
Please make sure that R package 'rj' (2.1 or compatible) is installed and that the R library paths are set correctly for the R environment configuration 'Rstatet36'.

I also defined again Preferences>Statet>R environment and Run Configurations to no effect.

Update: If you downvote a question, it would be favourable to add a comment, why you did this, so the question can be improved. Or deleted. Oh, well.


Solution

  • It was indeed the wrong Java Environment. The installation does not take long, if you know, what to do, but was rather tedious to find out:

    1) Install openjdk 8 on Ubuntu 18.04 with sudo apt install openjdk-8-jdk. I thought that simply changing the default Java version with sudo update-alternatives --config java might help but this was not the case. So don't do this.

    2) Go to Eclipse>Preferences>Java>Installed JREs: enter image description here There choose ADD and specify the folder, in this case /usr/lib/jvm/java-8-opdenjdk-amd64. Click OK.

    3) Go to Run>Run Configurations and double click on R console to open a new run configuration. Choose RJ (default)

    enter image description here

    4) Go to the tab JRE and choose Java 8 from Alternate JRE enter image description here

    5) Give your new configuration a nice name, click Apply and Run and your RJ console starts. At least it did in my environment.