Cannot connect to Java from R

In one of my builds (DatabaseConnector) I see this message:

checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include -I/usr/lib/jvm/java-8-openjdk-amd64/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server -ljvm'
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
checking whether -Xrs will be used... yes
checking whether JVM will be loaded dynamically... no
checking whether JNI programs can be compiled... yes
checking whether JNI programs run... 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.

In other builds (that depend on DatabaseConnector) I see:

Error: package or namespace load failed for ‘DatabaseConnector’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/travis/R/Library/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory

This same exact point in the branch was building fine a few days ago. We have a lot of packages that depend on rJava, and all our now showing this issue.

@jeroen and @jimhester, any thoughts what could cause this?

Links to example logs: https://api.travis-ci.org/v3/job/695872950/log.txt, https://api.travis-ci.org/v3/job/720585773/log.txt

I’ve also raised this issue with the developer of rJava.

I chime in to share I have the same issue, for example here. Like @schuemie, I also observed the cron jobs of multiple passing builds failed suddenly.

try running R CMD javareconf

I tried. When using just R CMD javareconf in the ‘before_install’ section I get

/opt/R/4.0.2/lib/R/bin/javareconf: 399: /opt/R/4.0.2/lib/R/bin/javareconf: cannot create /opt/R/4.0.2/lib/R/etc/Makeconf.new: Permission denied

See here for full log.

If I use sudo R CMD javareconf I get

sudo: R: command not found

See here for full log.

I’m sorry, I’m no expert at travis (or Linux for that matter), so I don’t know how to fix that.

I’m getting “TravisCI: error: …‘rJava’ had non-zero exit status” on GitHub but NOT on my local computer. Yesterday, 2020-09-13, was my first update since 2020-03-21. I use rJava only indirectly via the xlsx package. I’ve made very few changes since -03-21, and I don’t see how any of those changes could have generated this error.

Has a new version of rJava been installed that might cause problems like these?

@schuemie Try using sudo $(which R) CMD javareconf.

I had been having the same problems reported in this thread and opened a SO question. The code bit above was suggested in the answer and it worked out fine for me.

1 Like

Thanks @dhersz! That indeed fixes the builds for me.

Just to reiterate, the solution that works for me is adding this to travis.yml:

before_install:
  - sudo $(which R) CMD javareconf

You will obviously need to remove sudo: false if you have it.

Is there any way this could get incorporated into the R travis template so users don’t have to do this? Any way to fix this that allows for sudo: false?

Thanks @schuemie, for giving the complete solution! It works :+1:

Imprint