Configuring a .travis.yml for a package that depends on rJava?

I and a colleague have been working on a package that depends on rJava. The program we connect to needs Java 11+ to run, and we’re running into some problems while trying to configure the .travis.yml file.

language: r
warnings_are_errors: true
sudo: required
cache: packages

apt_packages:
  - r-cran-rjava

But I get the following error message:

Failed with error:  ‘.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’

Then I tried following the second approach:

language: r
warnings_are_errors: true
sudo: required
cache: packages

apt_packages:
  - default-jdk

before_install:
  - export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  - export PATH=$PATH:$JAVA_HOME/bin
  - export LD_LIBRARY_PATH=/usr/lib/jvm/java-11-openjdk-amd64/lib
  - sudo R CMD javareconf

To what I’m met with this error message:

sudo: R: command not found

The command "sudo R CMD javareconf" failed and exited with 1 during .

I have made a custom bash scripts that utilizes literals, but still no dice. this is right after I got docker up and running

Hello again @SolarUltima,

This is because R is in the user’s PATH, but if you run Isudo it ignores the argument and only looks in a few system locations. This can be solved easily by resolving the full path at the user level:

  - sudo $(which R) CMD javareconf

The above will insert the full path to R into the sudo command.

The javareconf script seems smart enough to detect Java in the standard locations and in standard libraries, so it isn’t necessary to export JAVA_HOME , PATH or LD_LIBRARY_PATH before calling it - although you could if you’d like with exceptions, (I’d make a bash script for this).

Here’s the .travis.yml file that I think would work flawlessly with what you’re trying to do:

language: r
cache: packages
warnings_are_errors: true
sudo: required

apt_packages:
  - r-cran-rjava

before_install:
  - sudo $(which R) CMD javareconf

If the above fails, you could try adding this into your .travis.yml as well:

r_packages:
  - rJava
1 Like