Search code examples
rtravis-cirjava

Using Travis with R and rJava


I have an R package which depends on rJava. I am using the R support for travis

language: r

sudo: required

warnings_are_errors: true

r_github_packages:
 - keboola/redshift-r-client

But it fails with error:

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/lib/R/site-library/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory

Complete log: https://travis-ci.org/keboola/provisioning-r-client/builds/61021633

I tried adding:

apt_packages:
 - openjdk-7-jre

or

jdk:
- oraclejdk8

But none seems to have any effect.

Solution 1:

language: r

sudo: required

apt_packages:
 - r-cran-rjava

Solution 2:

language: r

sudo: required

apt_packages:
 - openjdk-7-jre

before_install:
 - export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
 - export PATH=$PATH:$JAVA_HOME/bin
 - export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-oracle/lib/amd64:/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
 - sudo R CMD javareconf 

Solution

  • Please try to install r-cran-rjava directly via apt-get.

    There are a number of questions here on SO related to r-cran-rjava so glancing at those may help too. The Build-Depends for this package currently are default-jdk and the Depends is on openjdk-7-jre | default-jre. Relying on the package should help you there though.

    FWIW I still use the previous Travis setup as I find it loads faster.