2

I'm ultimately trying to install the RJDBC package on a mac running R 3.3.3 and Java 12 and Mojave OS.

When trying to install RDJBC I get the following error:

configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.

So then I go ahead and run R CMD javareconf in the terminal and I get the following error:

conftest.c:1:10: fatal error: 'jni.h' file not found

I've found various questions online around the same topic and have tried out suggested solutions and none have worked for me. Ity could be a combination of my OS/Java version. Would someone be willing to walk me through a fix here?

Update:

Stacktrace

WARNING: Initial Java 12 release has broken JNI support and does NOT work. Use stable Java 11 (or watch for 12u if avaiable).
ERROR: Java exception occurred during rJava bootstrap - see stderr for Java stack trace.
Exception in thread "main" java.lang.NullPointerException
    at java.base/jdk.internal.reflect.Reflection.verifyMemberAccess(Reflection.java:130)
    at java.base/java.lang.reflect.AccessibleObject.slowVerifyAccess(AccessibleObject.java:673)
    at java.base/java.lang.reflect.AccessibleObject.verifyAccess(AccessibleObject.java:666)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:638)
    at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075)
    at java.base/java.lang.reflect.Field.get(Field.java:416)
Error in .jcheck(silent = FALSE) : 
  java.lang.NullPointerException.jcall(f, "Ljava/lang/Object;", "get", .jcast(ic, "java/lang/Object"))new("jobjRef", jobj = <pointer: 0x7fd4a04ac4b8>, jclass = "java/lang/NullPointerException")

Interestingly, it seems to work when I run R through terminal, but not in Rstudio.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
ben890
  • 1,097
  • 5
  • 25
  • 56

1 Answers1

1

This will need some tweaking. In general, R, Java and rJava are not quite easy things to setup when they are supposed to work together. Make sure to go through: http://www.owsiak.org/r-java-11-and-making-sure-you-can-load-rjava/

Note that due to changes in Java 12 it is no longer possible to dynamically affect location of shared libraries via reflection - this affects rJava. I am pretty sure you won't get rJava and any other JNI based codes working properly with Java 12 in R.

Once you have your R configured, it will work as expected

> R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

...
...

> install.packages("RJDBC")
--- Please select a CRAN mirror for use in this session ---
...

> library(RJDBC)
Loading required package: DBI
>

Update

For Java 12 try following. Inside ~/.profile add following line

export JAVA_HOME=$(/usr/libexec/java_home -v 12)

then, run

> sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME}/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar

and, inside R

> system("java -version")
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
> library(RJDBC)
Loading required package: DBI
Loading required package: rJava
>

Of course, you still need XCode.app as it contains headers for JNI.

Update

In order to make sure all the apps are getting Java 11 instead of Java 12 (not only CLI based) you can "disable" Java 12 following way.

cd /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents
sudo mv Info.plist Info.plist~

Since now, even though you haven't removed Java 12, RStudio will pick up correct version.

enter image description here

Oo.oO
  • 12,464
  • 3
  • 23
  • 45