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.

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?

1 Like

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

After search thousand solutions, this solved my problem.
Thanks so much!

I’m having the same issue on Ubuntu 20.04 LTS and I’ve opened issues twice now on the official repository:

Completely remove Java

(base) mtg@mtg-ThinkPad-P53:~$ sudo dpkg --list | grep -i jdk
ii  default-jdk                                   2:1.11-72                                                                       amd64        Standard Java or Java compatible Development Kit
ii  default-jdk-headless                          2:1.11-72                                                                       amd64        Standard Java or Java compatible Development Kit (headless)
ii  openjdk-11-jdk:amd64                          11.0.10+9-0ubuntu1~20.04                                                        amd64        OpenJDK Development Kit (JDK)
ii  openjdk-11-jdk-headless:amd64                 11.0.10+9-0ubuntu1~20.04                                                        amd64        OpenJDK Development Kit (JDK) (headless)
ii  openjdk-11-jre:amd64                          11.0.10+9-0ubuntu1~20.04                                                        amd64        OpenJDK Java runtime, using Hotspot JIT
ii  openjdk-11-jre-headless:amd64                 11.0.10+9-0ubuntu1~20.04                                                        amd64        OpenJDK Java runtime, using Hotspot JIT (headless)
(base) mtg@mtg-ThinkPad-P53:~$ sudo apt-get remove --purge icedtea-* openjdk-*
## confirm deletion
(base) mtg@mtg-ThinkPad-P53:~$ java -version

Command 'java' not found, but can be installed with:

sudo apt install openjdk-11-jre-headless  # version 11.0.10+9-0ubuntu1~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-8-jre-headless   # version 8u282-b08-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless  # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless  # version 14.0.2+12-1~20.04

Install Java on Ubuntu for R

Following these instructions to install Installing RJava (Ubuntu) · hannarud/r-best-practices Wiki · GitHub

sudo apt-get install default-jdk
(base) mtg@mtg-ThinkPad-P53:~$ sudo apt-get install default-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java default-jdk-headless default-jre default-jre-headless openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless
Suggested packages:
  openjdk-11-demo openjdk-11-source visualvm fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
The following NEW packages will be installed:
  ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless
0 upgraded, 9 newly installed, 0 to remove and 14 not upgraded.
Need to get 0 B/263 MB of archives.
After this operation, 407 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package openjdk-11-jre-headless:amd64.
(Reading database ... 462977 files and directories currently installed.)
Preparing to unpack .../0-openjdk-11-jre-headless_11.0.10+9-0ubuntu1~20.04_amd64.deb ...
Unpacking openjdk-11-jre-headless:amd64 (11.0.10+9-0ubuntu1~20.04) ...
Selecting previously unselected package default-jre-headless.
Preparing to unpack .../1-default-jre-headless_2%3a1.11-72_amd64.deb ...
Unpacking default-jre-headless (2:1.11-72) ...
Selecting previously unselected package ca-certificates-java.
Preparing to unpack .../2-ca-certificates-java_20190405ubuntu1_all.deb ...
Unpacking ca-certificates-java (20190405ubuntu1) ...
Selecting previously unselected package openjdk-11-jre:amd64.
Preparing to unpack .../3-openjdk-11-jre_11.0.10+9-0ubuntu1~20.04_amd64.deb ...
Unpacking openjdk-11-jre:amd64 (11.0.10+9-0ubuntu1~20.04) ...
Selecting previously unselected package default-jre.
Preparing to unpack .../4-default-jre_2%3a1.11-72_amd64.deb ...
Unpacking default-jre (2:1.11-72) ...
Selecting previously unselected package openjdk-11-jdk-headless:amd64.
Preparing to unpack .../5-openjdk-11-jdk-headless_11.0.10+9-0ubuntu1~20.04_amd64.deb ...
Unpacking openjdk-11-jdk-headless:amd64 (11.0.10+9-0ubuntu1~20.04) ...
Selecting previously unselected package default-jdk-headless.
Preparing to unpack .../6-default-jdk-headless_2%3a1.11-72_amd64.deb ...
Unpacking default-jdk-headless (2:1.11-72) ...
Selecting previously unselected package openjdk-11-jdk:amd64.
Preparing to unpack .../7-openjdk-11-jdk_11.0.10+9-0ubuntu1~20.04_amd64.deb ...
Unpacking openjdk-11-jdk:amd64 (11.0.10+9-0ubuntu1~20.04) ...
Selecting previously unselected package default-jdk.
Preparing to unpack .../8-default-jdk_2%3a1.11-72_amd64.deb ...
Unpacking default-jdk (2:1.11-72) ...
Setting up default-jre-headless (2:1.11-72) ...
Setting up openjdk-11-jre-headless:amd64 (11.0.10+9-0ubuntu1~20.04) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jjs to provide /usr/bin/jjs (jjs) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jfr to provide /usr/bin/jfr (jfr) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode
update-binfmts: warning: current package is openjdk-11, but binary format already installed by openjdk-8
Setting up openjdk-11-jre:amd64 (11.0.10+9-0ubuntu1~20.04) ...
Setting up openjdk-11-jdk-headless:amd64 (11.0.10+9-0ubuntu1~20.04) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jar to provide /usr/bin/jar (jar) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jarsigner to provide /usr/bin/jarsigner (jarsigner) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc to provide /usr/bin/javadoc (javadoc) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/javap to provide /usr/bin/javap (javap) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jcmd to provide /usr/bin/jcmd (jcmd) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jdb to provide /usr/bin/jdb (jdb) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jdeprscan to provide /usr/bin/jdeprscan (jdeprscan) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jdeps to provide /usr/bin/jdeps (jdeps) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jimage to provide /usr/bin/jimage (jimage) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jinfo to provide /usr/bin/jinfo (jinfo) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jlink to provide /usr/bin/jlink (jlink) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jmap to provide /usr/bin/jmap (jmap) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jmod to provide /usr/bin/jmod (jmod) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jps to provide /usr/bin/jps (jps) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jrunscript to provide /usr/bin/jrunscript (jrunscript) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jshell to provide /usr/bin/jshell (jshell) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jstack to provide /usr/bin/jstack (jstack) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jstat to provide /usr/bin/jstat (jstat) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jstatd to provide /usr/bin/jstatd (jstatd) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmic to provide /usr/bin/rmic (rmic) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/serialver to provide /usr/bin/serialver (serialver) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jaotc to provide /usr/bin/jaotc (jaotc) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jhsdb to provide /usr/bin/jhsdb (jhsdb) in auto mode
Setting up default-jre (2:1.11-72) ...
Setting up default-jdk-headless (2:1.11-72) ...
Setting up openjdk-11-jdk:amd64 (11.0.10+9-0ubuntu1~20.04) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
Setting up ca-certificates-java (20190405ubuntu1) ...
head: cannot open '/etc/ssl/certs/java/cacerts' for reading: No such file or directory
Adding debian:Sonera_Class_2_Root_CA.pem
Adding debian:EC-ACC.pem
Adding debian:Certigna.pem
Adding debian:QuoVadis_Root_CA_2_G3.pem
Adding debian:QuoVadis_Root_CA_3_G3.pem
Adding debian:Security_Communication_Root_CA.pem
Adding debian:Buypass_Class_2_Root_CA.pem
Adding debian:Amazon_Root_CA_2.pem
Adding debian:SwissSign_Silver_CA_-_G2.pem
Adding debian:emSign_Root_CA_-_G1.pem
Adding debian:emSign_ECC_Root_CA_-_C3.pem
Adding debian:Chambers_of_Commerce_Root_-_2008.pem
Adding debian:SecureSign_RootCA11.pem
Adding debian:QuoVadis_Root_CA_2.pem
Adding debian:COMODO_Certification_Authority.pem
Adding debian:AffirmTrust_Commercial.pem
Adding debian:Starfield_Root_Certificate_Authority_-_G2.pem
Adding debian:Hellenic_Academic_and_Research_Institutions_ECC_RootCA_2015.pem
Adding debian:Go_Daddy_Root_Certificate_Authority_-_G2.pem
Adding debian:Actalis_Authentication_Root_CA.pem
Adding debian:TrustCor_ECA-1.pem
Adding debian:Autoridad_de_Certificacion_Firmaprofesional_CIF_A62634068.pem
Adding debian:OISTE_WISeKey_Global_Root_GB_CA.pem
Adding debian:Microsoft_ECC_Root_Certificate_Authority_2017.pem
Adding debian:AffirmTrust_Networking.pem
Adding debian:NAVER_Global_Root_Certification_Authority.pem
Adding debian:D-TRUST_Root_Class_3_CA_2_2009.pem
Adding debian:Microsec_e-Szigno_Root_CA_2009.pem
Adding debian:GlobalSign_Root_CA_-_R2.pem
Adding debian:Security_Communication_RootCA2.pem
Adding debian:OISTE_WISeKey_Global_Root_GC_CA.pem
Adding debian:DST_Root_CA_X3.pem
Adding debian:USERTrust_RSA_Certification_Authority.pem
Adding debian:GlobalSign_ECC_Root_CA_-_R5.pem
Adding debian:AC_RAIZ_FNMT-RCM.pem
Adding debian:TWCA_Global_Root_CA.pem
Adding debian:CA_Disig_Root_R2.pem
Adding debian:TWCA_Root_Certification_Authority.pem
Adding debian:DigiCert_Global_Root_G2.pem
Adding debian:ISRG_Root_X1.pem
Adding debian:DigiCert_Global_Root_G3.pem
Adding debian:IdenTrust_Commercial_Root_CA_1.pem
Adding debian:Trustis_FPS_Root_CA.pem
Adding debian:AffirmTrust_Premium.pem
Adding debian:GTS_Root_R3.pem
Adding debian:T-TeleSec_GlobalRoot_Class_2.pem
Adding debian:emSign_Root_CA_-_C1.pem
Adding debian:Entrust_Root_Certification_Authority_-_EC1.pem
Adding debian:Entrust_Root_Certification_Authority_-_G4.pem
Adding debian:SSL.com_Root_Certification_Authority_ECC.pem
Adding debian:TrustCor_RootCert_CA-2.pem
Adding debian:GeoTrust_Primary_Certification_Authority_-_G2.pem
Adding debian:CFCA_EV_ROOT.pem
Adding debian:SwissSign_Gold_CA_-_G2.pem
Adding debian:SSL.com_Root_Certification_Authority_RSA.pem
Adding debian:certSIGN_ROOT_CA.pem
Adding debian:Trustwave_Global_ECC_P256_Certification_Authority.pem
Adding debian:AffirmTrust_Premium_ECC.pem
Adding debian:TeliaSonera_Root_CA_v1.pem
Adding debian:Amazon_Root_CA_1.pem
Adding debian:Staat_der_Nederlanden_EV_Root_CA.pem
Adding debian:Entrust_Root_Certification_Authority_-_G2.pem
Adding debian:Entrust.net_Premium_2048_Secure_Server_CA.pem
Adding debian:NetLock_Arany_=Class_Gold=_Főtanúsítvány.pem
Adding debian:Atos_TrustedRoot_2011.pem
Adding debian:DigiCert_Global_Root_CA.pem
Adding debian:GDCA_TrustAUTH_R5_ROOT.pem
Adding debian:Secure_Global_CA.pem
Adding debian:Global_Chambersign_Root_-_2008.pem
Adding debian:DigiCert_Assured_ID_Root_CA.pem
Adding debian:VeriSign_Universal_Root_Certification_Authority.pem
Adding debian:Baltimore_CyberTrust_Root.pem
Adding debian:USERTrust_ECC_Certification_Authority.pem
Adding debian:GlobalSign_Root_CA_-_R3.pem
Adding debian:SSL.com_EV_Root_Certification_Authority_RSA_R2.pem
Adding debian:GTS_Root_R1.pem
Adding debian:COMODO_ECC_Certification_Authority.pem
Adding debian:GTS_Root_R4.pem
Adding debian:Certum_Trusted_Network_CA.pem
Adding debian:E-Tugra_Certification_Authority.pem
Adding debian:ePKI_Root_Certification_Authority.pem
Adding debian:Hongkong_Post_Root_CA_1.pem
Adding debian:certSIGN_Root_CA_G2.pem
Adding debian:SecureTrust_CA.pem
Adding debian:Microsoft_RSA_Root_Certificate_Authority_2017.pem
Adding debian:GlobalSign_Root_CA_-_R6.pem
Adding debian:UCA_Global_G2_Root.pem
Adding debian:COMODO_RSA_Certification_Authority.pem
Adding debian:Cybertrust_Global_Root.pem
Adding debian:UCA_Extended_Validation_Root.pem
Adding debian:TrustCor_RootCert_CA-1.pem
Adding debian:Amazon_Root_CA_3.pem
Adding debian:GlobalSign_Root_CA.pem
Adding debian:DigiCert_Trusted_Root_G4.pem
Adding debian:Hellenic_Academic_and_Research_Institutions_RootCA_2015.pem
Adding debian:Buypass_Class_3_Root_CA.pem
Adding debian:Hongkong_Post_Root_CA_3.pem
Adding debian:ACCVRAIZ1.pem
Adding debian:ssl-cert-snakeoil.pem
Adding debian:e-Szigno_Root_CA_2017.pem
Adding debian:Izenpe.com.pem
Adding debian:SSL.com_EV_Root_Certification_Authority_ECC.pem
Adding debian:emSign_ECC_Root_CA_-_G3.pem
Adding debian:T-TeleSec_GlobalRoot_Class_3.pem
Adding debian:XRamp_Global_CA_Root.pem
Adding debian:Hellenic_Academic_and_Research_Institutions_RootCA_2011.pem
Adding debian:DigiCert_Assured_ID_Root_G2.pem
Adding debian:Network_Solutions_Certificate_Authority.pem
Adding debian:Entrust_Root_Certification_Authority.pem
Adding debian:Starfield_Class_2_CA.pem
Adding debian:GTS_Root_R2.pem
Adding debian:D-TRUST_Root_Class_3_CA_2_EV_2009.pem
Adding debian:Starfield_Services_Root_Certificate_Authority_-_G2.pem
Adding debian:DigiCert_Assured_ID_Root_G3.pem
Adding debian:SZAFIR_ROOT_CA2.pem
Adding debian:TUBITAK_Kamu_SM_SSL_Kok_Sertifikasi_-_Surum_1.pem
Adding debian:Staat_der_Nederlanden_Root_CA_-_G3.pem
Adding debian:DigiCert_High_Assurance_EV_Root_CA.pem
Adding debian:Go_Daddy_Class_2_CA.pem
Adding debian:QuoVadis_Root_CA.pem
Adding debian:Trustwave_Global_Certification_Authority.pem
Adding debian:Trustwave_Global_ECC_P384_Certification_Authority.pem
Adding debian:Certigna_Root_CA.pem
Adding debian:QuoVadis_Root_CA_3.pem
Adding debian:Comodo_AAA_Services_root.pem
Adding debian:GlobalSign_ECC_Root_CA_-_R4.pem
Adding debian:Amazon_Root_CA_4.pem
Adding debian:QuoVadis_Root_CA_1_G3.pem
Adding debian:Certum_Trusted_Network_CA_2.pem
Adding debian:IdenTrust_Public_Sector_Root_CA_1.pem
done.
Setting up default-jdk (2:1.11-72) ...
Processing triggers for ca-certificates (20210119~20.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
(base) mtg@mtg-ThinkPad-P53:~$ sudo R CMD javareconf
*** JAVA_HOME is not a valid path, ignoring
Java interpreter : /usr/bin/java
Java version     : 11.0.10
Java home path   : /usr/lib/jvm/java-11-openjdk-amd64
Java compiler    : /usr/bin/javac
Java headers gen.: 
Java archive tool: /usr/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)/lib/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-fhxXXR/r-base-4.0.4=. -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,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-11-openjdk-amd64/lib/server -ljvm -L/usr/lib/R/lib -lR


JAVA_HOME        : /usr/lib/jvm/java-11-openjdk-amd64
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/lib/R
Done.
(base) mtg@mtg-ThinkPad-P53:~$ sudo apt-get install r-cran-rjava
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  r-cran-rjava
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 0 B/689 kB of archives.
After this operation, 1,900 kB of additional disk space will be used.
Selecting previously unselected package r-cran-rjava.
(Reading database ... 463503 files and directories currently installed.)
Preparing to unpack .../r-cran-rjava_0.9-13-1cran1.2004.0_amd64.deb ...
Unpacking r-cran-rjava (0.9-13-1cran1.2004.0) ...
Setting up r-cran-rjava (0.9-13-1cran1.2004.0) ...
(base) mtg@mtg-ThinkPad-P53:~$ sudo apt-get install libgdal-dev libproj-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libgdal-dev is already the newest version (3.0.4+dfsg-1build3).
libproj-dev is already the newest version (6.3.1-1).
0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded.
(base) mtg@mtg-ThinkPad-P53:~$ R

R version 4.0.4 (2021-02-15) -- "Lost Library Book"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("rJava")
Installing package into ‘/home/mtg/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/src/contrib/rJava_0.9-13.tar.gz'
Content type 'application/octet-stream' length 664898 bytes (649 KB)
==================================================
downloaded 649 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc -std=gnu99 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: ''
cpp flags   : '-I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux'
java libs   : '-L/usr/lib/jvm/java-11-openjdk-amd64/lib/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.
Warning in system(cmd) : error in running command
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/mtg/R/x86_64-pc-linux-gnu-library/4.0/rJava’

The downloaded source packages are in
	‘/tmp/RtmpnCU9i4/downloaded_packages’
Warning message:
In install.packages("rJava") :
  installation of package ‘rJava’ had non-zero exit status
> 
(base) mtg@mtg-ThinkPad-P53:~$ sudo $(which R) CMD javareconf
[sudo] password for mtg: 
*** JAVA_HOME is not a valid path, ignoring
Java interpreter : /usr/bin/java
Java version     : 11.0.10
Java home path   : /usr/lib/jvm/java-11-openjdk-amd64
Java compiler    : /usr/bin/javac
Java headers gen.: 
Java archive tool: /usr/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)/lib/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-fhxXXR/r-base-4.0.4=. -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,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-11-openjdk-amd64/lib/server -ljvm -L/usr/lib/R/lib -lR


JAVA_HOME        : /usr/lib/jvm/java-11-openjdk-amd64
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /usr/lib/R
Done.

(base) mtg@mtg-ThinkPad-P53:~$ R

R version 4.0.4 (2021-02-15) -- "Lost Library Book"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages('rJava')
Installing package into ‘/home/mtg/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://mirror.rcg.sfu.ca/mirror/CRAN/src/contrib/rJava_0.9-13.tar.gz'
Content type 'application/octet-stream' length 664898 bytes (649 KB)
==================================================
downloaded 649 KB

* installing *source* package ‘rJava’ ...
** package ‘rJava’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
configure: checking whether gcc -std=gnu99 supports static inline...
yes
checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: ''
cpp flags   : '-I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux'
java libs   : '-L/usr/lib/jvm/java-11-openjdk-amd64/lib/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.
Warning in system(cmd) : error in running command
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/mtg/R/x86_64-pc-linux-gnu-library/4.0/rJava’

The downloaded source packages are in
	‘/tmp/RtmpbW4NC2/downloaded_packages’
Warning message:
In install.packages("rJava") :
  installation of package ‘rJava’ had non-zero exit status

It turns out this config.log file is never generated: Error says to check config.log for failure but the file is not being generated · Issue #256 · s-u/rJava · GitHub
Therefore, I’m still unable to resolve this issue

The working solution I found was this: java - "Unable to run a simple JNI program" error message when installing rJava on R 3.6 for ubuntu bionic beaver - Stack Overflow