# Force a .travis.yml for a package that depends on rJava?

**URL:** <https://travis-ci.community/t/force-a-travis-yml-for-a-package-that-depends-on-rjava/11036>\
**Category:** Deployment\
**Tags:** travis-build\
**Created:** [January 15, 2021, 6:51am UTC](https://travis-ci.community/t/force-a-travis-yml-for-a-package-that-depends-on-rjava/11036 "2021-01-15T06:51:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SolarUltima](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/solarultima/32/4019_2.png) [@SolarUltima](https://travis-ci.community/u/SolarUltima)\
**Post date:** [January 15, 2021, 6:51am UTC](https://travis-ci.community/t/force-a-travis-yml-for-a-package-that-depends-on-rjava/11036/1 "2021-01-15T06:51:43Z")

</div>

I (and some colleagues) 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.

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

apt_packages:
  - r-cran-rjava

```

I get error:

```bash
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 tweak the yml file a bit:

```auto
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

```

error I get then:

```bash

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

```

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [January 15, 2021, 6:54am UTC](https://travis-ci.community/t/force-a-travis-yml-for-a-package-that-depends-on-rjava/11036/2 "2021-01-15T06:54:55Z")

</div>

This is because `R` is in the user’s `PATH`, but `sudo` ignores it and only looks in a few system locations now. This can be solved easily by resolving the full `PATH` at the user level, you could also just use a bash script for the sake of time I’ll show you my fix:

```auto
  - sudo $(which R) CMD javareconf

```

This will insert the full `PATH` to `R` into the sudo command.

Note that the `javareconf` script seems smart enough to detect Java in the standard locations, (stdlibs) so it isn’t necessary to export `JAVA_HOME` , `PATH` or `LD_LIBRARY_PATH` before calling it, as Java already knows.

After some ‘problem solving’ I ended up with the following `.travis.yml` file:

```auto
---
language: r
cache: packages
warnings_are_errors: true
sudo: required

apt_packages:
  - r-cran-rjava

before_install:
  - sudo $(which R) CMD javareconf

```

I hope this helps, let me know if this works/doesn’t work and we can figure it out.
