Skip to content

So nearly there, but can't install rJava

10 messages · Chris Evans, Dirk Eddelbuettel, Enrico Schumann +2 more

#
Wow, this has amplified my respect and gratitude for the R Debian repositories. Doing all the install.packages() and following the clues about missing dependencies has taken hours! However, I have almost all the packages I want installed on this machine and Rstudio and the shiny server are installed and running fine. Bizarrely, to my mind, I am totally failing on rJava and hence a number of packages that depend on it. In R I get: 

checking Java support in R... present: 
interpreter : '/usr/lib/jvm/default-java/jre/bin/java' 
archiver : '' 
compiler : '' 
header prep.: '' 
cpp flags : '' 
java libs : '' 
configure: error: Java Development Kit (JDK) is missing or not registered in R 
Make sure R is configured with full Java support (including JDK). Run 
R CMD javareconf 
as root to add Java support to R. 


When I do R CMD javareconf I get this: 

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# R CMD javareconf 
Java interpreter : /usr/lib/jvm/default-java/jre/bin/java 
Java version : 1.8.0_181 
Java home path : /usr/lib/jvm/default-java 
Java compiler : /usr/lib/jvm/default-java/bin/javac 
Java headers gen.: /usr/lib/jvm/default-java/bin/javah 
Java archive tool: /usr/lib/jvm/default-java/bin/jar 

trying to compile and link a JNI program 
detected JNI cpp flags : 
detected JNI linker flags : 
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/home/jranke/git/r-backports/stretch/r-base-3.5.2=. -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 
#include <jni.h> 
^ 
compilation terminated. 
/usr/lib/R/etc/Makeconf:162: recipe for target 'conftest.o' failed 
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. 

I'm pretty sure that the problem is with some missing path but I also know I'm out of my depth (again). I'm a bit puzzled because I have only installed default Debian things. Do I need particular non-default Java or Java related components? 

TIA (again!), 

Chris
#
Am Dienstag, 22. Januar 2019, 08:27:14 CET schrieb Chris Evans:
...
You get a complaint that jni.h is missing. So one strategy would be to look 
for this file in the available packages:

  sudo apt-file search jni.h

One of the packages returned is openjdk-8-jdk-headless (which I happen to have 
installed). I think (others will know for certain) that you need a Java 
Development Kit (jdk) not just a runtime environment (jre).

Cheers,

Johannes
#
As ever, I learn from this: I didn't know apt-file. Got it, installed it, used it: 

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# apt-file search jni.h 
android-libnativehelper-dev: /usr/include/android/nativehelper/jni.h 
android-platform-frameworks-native-headers: /usr/include/android/android/asset_manager_jni.h 
android-platform-frameworks-native-headers: /usr/include/android/android/native_window_jni.h 
gcj-6-jdk: /usr/lib/gcc/x86_64-linux-gnu/6/include/jni.h 
gcj-6-jdk: /usr/lib/jvm/java-1.5.0-gcj-6-amd64/include/jni.h 
libavcodec-dev: /usr/include/x86_64-linux-gnu/libavcodec/jni.h 
libgluegen2-build-java: /usr/share/gluegen2/make/stub_includes/jni/jni.h 
openjdk-8-jdk-headless: /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h 

I was 99% sure I already had that last installed. Sure enough: 

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# apt-get install openjdk-8-jdk-headless 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
openjdk-8-jdk-headless is already the newest version (8u181-b13-2~deb9u1). 
openjdk-8-jdk-headless set to manually installed. 
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

Anyone else got any ideas? 

Chris

  
    
#
On 22 January 2019 at 10:14, Chris Evans wrote:
| Anyone else got any ideas? 

Java can be tricky and that is one of the reasons we have r-cran-rjava
prebuilt for you. It should resolve issues and work because other binary
packages depend on it.

Otherwise, as Johannes hinted, you need a JDK if you build with rJava from
CRAN source, and 'sudo R CMD javareconf' should work.  

I don't do much work on Debian stable so no concrete tips from me.

Dirk
#
On 22 January 2019 at 10:14, Chris Evans wrote:
| root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# apt-get install openjdk-8-jdk-headless 
| Reading package lists... Done 
| Building dependency tree 
| Reading state information... Done 
| openjdk-8-jdk-headless is already the newest version (8u181-b13-2~deb9u1). 
| openjdk-8-jdk-headless set to manually installed. 
| 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 
| 
| Anyone else got any ideas? 

Install the full-blown jdk no just headless.

In the sources for rJava I have as a build-depends

   openjdk-10-jdk

which may of course be a virtual. At some point we had more than JDK
implementation.  See what you can find there.

Dirk
#
Chris> As ever, I learn from this: I didn't know apt-file. Got it, installed it, used it: 
    Chris> root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# apt-file search jni.h 
    Chris> android-libnativehelper-dev: /usr/include/android/nativehelper/jni.h 
    Chris> android-platform-frameworks-native-headers: /usr/include/android/android/asset_manager_jni.h 
    Chris> android-platform-frameworks-native-headers: /usr/include/android/android/native_window_jni.h 
    Chris> gcj-6-jdk: /usr/lib/gcc/x86_64-linux-gnu/6/include/jni.h 
    Chris> gcj-6-jdk: /usr/lib/jvm/java-1.5.0-gcj-6-amd64/include/jni.h 
    Chris> libavcodec-dev: /usr/include/x86_64-linux-gnu/libavcodec/jni.h 
    Chris> libgluegen2-build-java: /usr/share/gluegen2/make/stub_includes/jni/jni.h 
    Chris> openjdk-8-jdk-headless: /usr/lib/jvm/java-8-openjdk-amd64/include/jni.h 

    Chris> I was 99% sure I already had that last installed. Sure enough: 

    Chris> root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# apt-get install openjdk-8-jdk-headless 
    Chris> Reading package lists... Done 
    Chris> Building dependency tree 
    Chris> Reading state information... Done 
    Chris> openjdk-8-jdk-headless is already the newest version (8u181-b13-2~deb9u1). 
    Chris> openjdk-8-jdk-headless set to manually installed. 
    Chris> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

    Chris> Anyone else got any ideas? 

    Chris> Chris 

I have not followed the discussion closely, so my
apologies if I am off-topic. But on Ubuntu 18.04 at
least you can run

  sudo apt install openjdk-11-jdk
  R CMD javareconf -e

and then in R

  install.packages("rJava")

should work.

kind regards
        Enrico

    >> From: "Johannes Ranke" <johannes.ranke at jrwb.de>
    >> To: "r-sig-debian" <r-sig-debian at r-project.org>, "Chris Evans"
    >> <chrishold at psyctc.org>
    >> Sent: Tuesday, 22 January, 2019 08:47:28
    >> Subject: Re: [R-sig-Debian] So nearly there, but can't install rJava

    >> Am Dienstag, 22. Januar 2019, 08:27:14 CET schrieb Chris Evans:

    >> ...

    >> > error: jni.h: No such file or directory

    >> > #include <jni.h>

    >> > ^

    >> > compilation terminated.

    >> You get a complaint that jni.h is missing. So one strategy would be to look for
    >> this file in the available packages:

    >> sudo apt-file search jni.h

    >> One of the packages returned is openjdk-8-jdk-headless (which I happen to have
    >> installed). I think (others will know for certain) that you need a Java
    >> Development Kit (jdk) not just a runtime environment (jre).

    >> Cheers,

    >> Johannes

    Chris> -- 
    Chris> Chris Evans <chris at psyctc.org> Skype: chris-psyctc 
    Chris> Visiting Professor, University of Sheffield <chris.evans at sheffield.ac.uk> 
    Chris> I do some consultation work for the University of Roehampton <chris.evans at roehampton.ac.uk> and other places but this <chris at psyctc.org> remains my main Email address. 
    Chris> I have "semigrated" to France, see: https://www.psyctc.org/pelerinage2016/semigrating-to-france/ if you want to book to talk, I am trying to keep that to Thursdays and my diary is now available at: https://www.psyctc.org/pelerinage2016/ecwd_calendar/calendar/ 
    Chris> Beware: French time, generally an hour ahead of UK. That page will also take you to my blog which started with earlier joys in France and Spain!
#
Thanks Dirk and Enrico,

First clarification: I'm in this mess because I'm trying to run R 3.5.2 within Debian stable (9/"sretch") using the stretch-cran35 repository. That uses and provides r-api-35 but many of the packages depend upon r-api-3.  As Johannes said a day or so back, the way around this is to use install.packages() in R to get the packages you want. That leads you into quite a lot of manual identification of dependencies and I worked through all the ones I hit until I was left with the only packages I use that I can't install sharing just one dependency: they all depend on rJava and I can't install from the r-cran-rjava package in the stretch-cran35 repository because that's one of the packages that depends on r-api-3.  

I thought that installing the default java and jdk Debian packages and using R CMD javareconf (as root) would set the right variables for install.packages("rJava") to work but no go.  It fails with this information:

checking Java support in R... present:
interpreter : '/usr/lib/jvm/default-java/jre/bin/java'
archiver    : '/usr/lib/jvm/default-java/bin/jar'
compiler    : '/usr/lib/jvm/default-java/bin/javac'
header prep.: '/usr/lib/jvm/default-java/bin/javah'
cpp flags   : ''
java libs   : ''
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 ?/usr/local/lib/R/site-library/rJava?

I think the problem may be options setting where R/rJava will look for Java so I tried:
$java.home
[1] "/usr/lib/jvm/java-8-openjdk-amd64/"

but that doesn't change things. 

As far as I can see Debian is happy with the setup of java and javac:

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# javac -version
javac 1.8.0_181
root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# update-alternatives --config javac
There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
Nothing to configure.
root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.
root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# 

And I have the full jdk not just the headless version I can see the header files:

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# ls -lsart /usr/lib/jvm/java-8-openjdk-amd64/include/
total 220
80 -rw-r--r-- 1 root root 78425 Oct 22 19:05 jvmti.h
 8 -rw-r--r-- 1 root root  4771 Oct 22 19:05 jvmticmlr.h
76 -rw-r--r-- 1 root root 74698 Oct 22 19:05 jni.h
 8 -rw-r--r-- 1 root root  7404 Oct 22 19:05 jdwpTransport.h
12 -rw-r--r-- 1 root root  9687 Oct 22 19:05 jawt.h
24 -rw-r--r-- 1 root root 21125 Oct 22 19:05 classfile_constants.h
 4 drwxr-xr-x 2 root root  4096 Jan 22 08:09 linux
 4 drwxr-xr-x 3 root root  4096 Jan 22 08:09 .
 4 drwxr-xr-x 8 root root  4096 Jan 22 12:55 ..
root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# 

But I can't reconfigure R for Java:

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# R CMD javareconf
*** JAVA_HOME is not a valid path, ignoring
Java interpreter : /usr/lib/jvm/default-java/jre/bin/java
/usr/lib/R/bin/javareconf: 1: /usr/lib/R/bin/javareconf: /usr/lib/jvm/default-java/jre/bin/java: not found


*** Java interpreter doesn't work properly.

root at DebianAdvent:/home/chris/Downloads/gmp-6.1.2# 

I hope this helps someone see something I can fix!

Tangential question: surely I'm not rare in running R 3.5.2 on Stretch am I?  
Other tangential question: is there anything that can be done to fix the r-api-3/r-api-3.5 issue.  You can see I'm no programmer or sysadmin but if there is anything I can do to help ...?

TIA all,

Chris



----- Original Message -----

  
    
#
Hi Chris,
so I tried:
This should not be necessary. I would recommend to start a fresh R session in 
order to unset this.
...
...
as above, I would not recommend setting JAVA_HOME manually.
Obviously this file was not found. Again, apt-file can provide some help (but 
not when giving it the full path, because of the link maintained by update-
alternatives:

  apt-file search jre/bin/java

If you have openjdk-8-jre-headless installed, this file should be there on your 
system. Seems you don't have the jre installed?

...
I for sure am running it without issues on several computers. On my desktop, I 
am using openjdk-9 from stretch-backports, but on my laptop I just upgraded 
from R 3.4.x to R 3.5.2 using the stretch-cran35 packages on CRAN, and had no 
issues. I could install rJava from within R, and after that R CMD javareconf 
gives me:

Java interpreter : /usr/lib/jvm/default-java/jre/bin/java
Java version     : 1.8.0_181
Java home path   : /usr/lib/jvm/default-java
Java compiler    : /usr/lib/jvm/default-java/bin/javac
Java headers gen.: /usr/lib/jvm/default-java/bin/javah
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)/jre/lib/amd64/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=/home/jranke/git/r-backports/stretch/r-base-3.4.3=. -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,-z,relro -o conftest.so conftest.o 
-L/usr/lib/jvm/default-java/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR


JAVA_HOME        : /usr/lib/jvm/default-java
Java library path: $(JAVA_HOME)/jre/lib/amd64/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
Thanks for the offer. Personally, I am always glad to get some feedback from 
people using the Debian backports on CRAN, so thanks for that. On the other 
hand, I do not think that there is an error to be fixed. Of course it would be 
nice if we could provide more precompiled debs for these backports in order to 
avoid having to install them from sources. For me personally, this is not a 
priority, I am happy if I manage to get the base and recommended packages out 
on new releases.

Johannes

  
    
#
On 22 January 2019 at 15:18, Johannes Ranke wrote:
| Thanks for the offer. Personally, I am always glad to get some feedback from 
| people using the Debian backports on CRAN, so thanks for that. On the other 
| hand, I do not think that there is an error to be fixed. Of course it would be 
| nice if we could provide more precompiled debs for these backports in order to 
| avoid having to install them from sources. For me personally, this is not a 
| priority, I am happy if I manage to get the base and recommended packages out 
| on new releases.

Right.

And for what it is worth we do have several working choices -- and eg the
Ubuntu side has over 4000 r-cran-* binary packages for the LTS releases (ie
Ubuntu's variant of stable).  Debian testing has fewer, but it a little more
current on other things. And one can always mix and match binary
installations and from CRAN installation.  Most users should find their
preferred way among these choices.

It should be said, though, that Chris did chose what at least to me appears
to be the most constrained choice.

Dirk
#
Dear Chris,

Maybe you could try debugging the error
based on the underlying javareconf script.

Scrolling through
we can see that the script exits from
found at /usr/lib/jvm/default-java/jre/bin/java, but the subsequent call
failed / didn't return the expected test result.

You could try to run that code manually and see what you get and where
the problem is:
NB: the variable R_SHARE_DIR is set in the `which R` script.

Good luck!

	Sebastian


Am 22.01.19 um 14:45 schrieb Chris Evans: