3
votes

I continue to have trouble installing and loading rJava. I have R 3.4.1 ('Single Candle'); Java v 9 and mac OS 10.12.6.

I followed all of the steps listed here which included using Terminal to edit my ~/.profile to include:

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

export PATH=$JAVA_HOME/bin:$PATH

And making other changes to connect R to the 'right' Java. When I run

sudo R CMD javareconf

however, I get an error message that says:

warning: ‘JNI_CreateJavaVM’ is deprecated [-Wdeprecated-declarations] JNI_CreateJavaVM(0, 0, 0); ^ /System/Library/Frameworks/JavaVM.framework/Headers/jni.h:1937:1: note: ‘JNI_CreateJavaVM’ has been explicitly marked deprecated here JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args); ^ 1 warning generated.

And when I run

R CMD INSTALL rJava_0.9-8.tar.gz

Everything goes smoothly until I get an error that says:

checking whether JNI programs can be compiled… configure: error: Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R. If in doubt, re-run “R CMD javareconf” as root.

ERROR: configuration failed for package ‘rJava’

Michal from the site linked above kindly suggested to make sure that '/usr/libexec/java_home -v 9' "points" to JDK and not JRE. I am not sure how to do this. Also when I try something like:

echo $JAVA_HOME

I get:

/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home

How do I know if this JDK or JRE?

Due to my error messages, I think I have a JNI problem, but I am not sure how to go about STARTING to deal with that issue. Any insight regarding what might have gone wrong using Michal's tutorial would be greatly appreciated!

P.S. My original issue was in R, trying to load library(rJava) and getting this error:

Error: package or namespace load failed for ‘rJava’: .onLoad failed in loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so Reason: image not found

2

2 Answers

0
votes

I followed this link, especially:

Administrator account user

Issue the following commands at the terminal:

export JAVA_HOME=${JAVA_HOME:-$(/usr/libexec/java_home)} 
export LIBJVM=$(find "${JAVA_HOME}" -name 'libjvm.dylib')
R CMD javareconf JAVA_LIBS="${LIBJVM}" JAVA_LD_LIBRARY_PATH="${LIBJVM}" JAVA_CPPFLAGS="'-I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin -I$(dirname "${LIBJVM}")'"
ln -fs "$LIBJVM" /Library/Frameworks/R.framework/Libraries

The installation worked!

0
votes

You can do following to test whether your Java 9 is JDK. Do following:

> git clone https://github.com/mkowsiak/jnicookbook.git
> cd jnicookbook/recipes/recipeNo001
> export JAVA_HOME=$(/usr/libexec/java_home -v 9)
> export PATH=$JAVA_HOME/bin:$PATH
> make
> make test

If you see

Hello world!

at the end, it means your JDK can compile JNI code. Now, if it works, it means rJava is still using incorrect Java installation (e.g. one from Apple). In that case, you need to take a look inside error log of rJava to make sure what is used there.

I hope this will help you at least a little bit.