1

I recently updated to the latest R version and Mojave. I can't get Rjava to work anymore. I tried reading the many topics on this, but I can't figure out what I am doing wrong...

Loading required package: rJava
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.5/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
  Reason: image not found
Error: package ‘rJava’ could not be loaded
enter this into terminal...
 /usr/libexec/java_home -V

Matching Java Virtual Machines (2):
    10.0.1, x86_64: "Java SE 10.0.1"    /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_171, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home

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

When I run

 sudo R CMD javareconf



Java interpreter : /usr/bin/java
Java version     : 10.0.1
Java home path   : /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
System Java on macOS

trying to compile and link a JNI program 
detected JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
detected JNI linker flags : -framework JavaVM
x86_64-apple-darwin13.4.0-clang -I/anaconda3/lib/R/include -DNDEBUG -I/System/Library/Frameworks/JavaVM.framework/Headers  -D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -I/anaconda3/include   -fPIC  -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -I/anaconda3/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix  -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program, ignoring this though as you may not want to compile anything here
.. this is an Anaconda Distribution and conda-forge customization whereby env activation causes us
.. to call R CMD javareconf in order to dynamically detect a JDK that may be in that env. The fact
.. that we prohibit setting LD_LIBRARY_PATH is also somewhat responsible for us needing to do this
.. because ${R_HOME}/etc/ldpaths is the normal way that R dynamically finds shared libraries. This
.. is what would, in upstream R, set LD_LIBRARY_PATH. AD cannot set this as it causes all sorts of
.. issues with DT_RUNPATH / DT_RPATH on various distributions.


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Java library path: 
JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
JNI linker flags : -framework JavaVM
Updating Java configuration in /anaconda3/lib/R
Done.

Can someone tell me what I have to do? I'm sure this has been repeated many times and is obvious but I cant figure it out or do it correctly.

2 Answers 2

2

Jumping between Mac OS versions, Java versions and rJava releases might be a struggle.

Take a look here for quite comprehensive list of steps you might need to take:

http://www.owsiak.org/r-3-4-rjava-macos-and-even-more-mess/

It might be you need to recompile rJava from sources to get it working in your environment.

Sign up to request clarification or add additional context in comments.

Comments

0

reposting the quickest and most effective from https://github.com/rstudio/rstudio/issues/2750

sudo ln -s $(/usr/libexec/java_home)/lib/server/libjvm.dylib /usr/local/lib

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.