Skip to content

Problem with RJDBC in OS X 10.11

5 messages · MacQueen, Don, Berend Hasselman, Charles DiMaggio +1 more

#
I?m not sure the best place to ask about this, so I?ll start here, since the problem appears to be configuring Java on a Mac to support R packages. Unfortunately, my understanding of how to configure and manage Java is essentially non-existent, so any suggestions would be much appreciated. 

I have a script using RJDBC that is working on a Mac running OS X 10.10.5. The same script, with the same JDBC .jar files from Oracle, is not working on an OS X 10.11.4 machine, as shown below. Other packages that depend on Java, such as xlsx, are not working either.

I have run R CMD javareconf to no avail (output below).

The software management system used by our IT department claims that "Oracle Java 1.7 SDK and JRE" are installed.

-Don
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(classPath) : JNI_GetCreatedJavaVMs returned -1
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RJDBC_0.2-5 rJava_0.9-8 DBI_0.4-1  



[macqueen1-ml:~]% sudo R CMD javareconf

Java interpreter : /usr/bin/java
Java version     : 1.7.0_101
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.7.0_101.jdk/Contents/Home/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Non-system Java on OS X

trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.7.0_101.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.7.0_101.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.7.0_101.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.7.0_101.jdk/Contents/Home/jre
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.


Also:
[macqueen1-ml:~]% java -version
java version "1.7.0_101"
Java(TM) SE Runtime Environment (build 1.7.0_101-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.101-b14, mixed mode)



Don MacQueen
Lawrence Livermore National Laboratory
macqueen1 at llnl.gov
925-423-1062
#
I had similar issues with rJava. See this thread: https://stat.ethz.ch/pipermail/r-sig-mac/2016-February/011836.html

I made a shell script for reinstalling rJava whenever the R version changes.
It runs in the folder where you have the rJava source tarball.

<script>
R -e 'Sys.getenv("DYLD_FALLBACK_LIBRARY_PATH")'
R CMD javareconf
R -e 'Sys.getenv("DYLD_FALLBACK_LIBRARY_PATH")'

RMAINLIB="$(R RHOME)/library"
# install rJava from source in to main library
R CMD INSTALL --library="$RMAINLIB" rJava_0.9-8.tar.gz > install.out
</script>

I've just tested this after removing the installed version of rJava.
I can load things like XLConnect etc. without problems.

Then you can use rJava etc. with R in Terminal. Using rJava doesn't work in/with R GUI.

Berend
#
Recently came up against the same issue with package ?RNetLogo?, so appears to not be an isolated issue.  Solution for me was to 

(1) ensure latest version of java (type "java -version" without the quotes in your terminal), if less than 1.8, install Java SE Development Kit 8u91 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) and 

(2) run the program through JGR.  I needed to tweak the settings a bit when running JGR:

Sys.setenv(NOAWT=1)
library(JGR)
Sys.unsetenv("NOAWT")
JGR()

Wasn?t entirely happy about having to leave my preferred editor (Textmate), but it worked.

Cheers

Charles
Charles DiMaggio, PhD, MPH
Professor of Surgery and Population Health
Director of Injury Research
Department of Surgery
New York University School of Medicine
462 First Avenue, NBV 15
New York, NY 10016-9196
Charles.Dimaggio at nyumc.org
Office: 212.263.3202
Mobile: 516.308.6426
On Jun 18, 2016, at 3:43 AM, Berend Hasselman <bhh at xs4all.nl> wrote:

            

  
  
#
I recently had failure on an El Capitan machine running R 3.3.0 RC  to load pkg:XLConnect and got identical message attempting to load pkg:xlsx. 

#------------
Loading required package: XLConnectJars
Error : .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.3/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so
  Reason: image not found
Error: package ?XLConnectJars? could not be loaded
#------------

Searching StackOverflow I found an answer that reported success with this system level incantation:

david-winsemiuss-mac-pro:~ davidwinsemius$ sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
Password:

# I (think) this creates a link to the current libjvm in the "newly blessed" OSX library location under the tightened OSX rules of user engagement. Then success with both packages loading. Now get:

$ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(?) 64-Bit Server VM (build 25.65-b01, mixed mode)

I didn't know if my R sessions would have the same result, since I had both a 1.6 which I thought was the designated Java version for R, and a 1.8 version of the Java RTE, but seems I'm now simply using 1.8.
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(?) 64-Bit Server VM (build 25.65-b01, mixed mode)
David Winsemius
Alameda, CA, USA
2 days later
#
Berend,

I now have  working packages, thanks!

The key was installing rJava from source rather than binary (binary being the default when using install.packages(); I had already run javareconf so there was no change there).

And apologies to everyone for failing to search hard enough to find the solution that was already available on R-sig-mac. As an aside, yes, my Java is indeed old, but my institution, for whatever reason, is not offering a more recent version in its software deployment system.

-Don

Don MacQueen
Lawrence Livermore National Laboratory
macqueen1 at llnl.gov
925-423-1062