14

I installed rJava by calling install.packages("rJava") -- no problems seen

However when I call:

library(rJava)
.jinit() 

I get:

JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
Error in .jinit() : JNI_GetCreatedJavaVMs returned -1

I'm running OSX:

Darwin MBP-2 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64

I have the following Sun JDK's installed:

$ ls /Library/Java/JavaVirtualMachines/
jdk1.7.0_79.jdk jdk1.8.0_65.jdk

Which Java is on my PATH:

$ which java
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home//bin/Java

I also have JavaHome defined as:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/
user1172468
  • 5,306
  • 6
  • 35
  • 62
  • 2
    How did you configure R? Note that rJava will use whichever Java you configured in R - see `R CMD javareconf` and the R documentation. Also avoid setting `JAVA_HOME` by hand - you can only break things by setting it wrong. Finally, make sure you use rJava 0.9-8 or higher since you're on OS X and there are several bugs in Oracle Java there that need work-arounds. – Simon Urbanek Jan 25 '16 at 18:53
  • Let me try that out -- thanks. – user1172468 Jan 25 '16 at 20:36
  • 1
    @user1172468 did it finally work for you? I still have the issue – Dinesh Apr 28 '16 at 17:26
  • @Dinesh, I fiexed it -- don't remember the fix unfortunately :-( – user1172468 May 10 '16 at 14:08

5 Answers5

9

The answer at https://stackoverflow.com/a/36045290/4351357 helped resolve this issue for me on MacOS Sierra Version 10.12. In particular, it provided the code in command 1, below.

The three Terminal commands I used are:

  1. sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
  2. sudo R CMD javareconf
  3. install.packages("rJava",type='source')
Community
  • 1
  • 1
Jonathan
  • 125
  • 1
  • 9
6

This solution Cannot load R xlsx package on Mac OS 10.11

sudo R CMD javareconf

install.packages("rJava",type='source')

Worked for me

Community
  • 1
  • 1
Tim Child
  • 2,994
  • 1
  • 26
  • 25
1

While attempting to run this test on OSX 10.11.5 (El Capitan) http://www.r-bloggers.com/connecting-r-to-an-oracle-database-with-rjdbc/

I kept getting that same error. I attempted to just do the install as suggested by Tim Child. The thing I noticed was that my version of R Studio (Version 0.99.896 ) kept complaining about installing the 1.6 Legacy Java for OSX.

I installed the legacy Java from the website https://support.apple.com/kb/DL1572?locale=en_US

Then ran a simpler test in R Studio.

library(rJava)

.jinit()
print(.jcall("java/lang/System", "S", "getProperty", "java.version"))

My results:

 > library(rJava)
 > .jinit()
 > print(.jcall("java/lang/System", "S", "getProperty", "java.version"))
[1] "1.6.0_65"

Happy to see that I ran my other test (then that one that started me down this path). I still could not get it to set the most current Java version.

I did one more re-install of the package rJava

install.packages("rJava",type='source')

and things are working ok, using version of Java 1.6 for now, but at least I can get some work done. Hope some comes across a better fix :)

mtbiker-s
  • 11
  • 1
0

I struggled with this issue for a couple of hours. There was a really good thread with some background on rJava here: https://groups.google.com/forum/#!topic/r-sig-mac/eFSDrjphgGs

The following steps ended up working for me:
(1) Upgrade to the latest JDK

(2) Set the following environment variables in my ~/.bash_profile:
export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_CPPFLAGS=$(/usr/libexec/java_home)/include

(3) Re-install rJava from source as root:
sudo R CMD INSTALL rJava_0.9-8.tar.gz

(4) Re-configure Java as root:
sudo R CMD javareconf

Then I could properly install other libraries that depended on the correct configuration of rJava.

0

This helped me:

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/lib/libserver.dylib

fycth
  • 3,410
  • 25
  • 37