无法在Mac OS 10.11上加载R xlsx软件包

Mat*_*gen 40 java macos r

我可以加载rJava和xlsxjars包,但是当我执行库(xlsx)时,我得到了"无法加载JVM".以下是我的详细信息.

OS版本:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11
BuildVersion:   15A284
Run Code Online (Sandbox Code Playgroud)

Java版本:

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

Java路径:

$ which java
/usr/bin/java
Run Code Online (Sandbox Code Playgroud)

Java主页:

$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
Run Code Online (Sandbox Code Playgroud)

R版本:

$ R --version
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Run Code Online (Sandbox Code Playgroud)

我如何推出R:

$ LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio
Run Code Online (Sandbox Code Playgroud)

成功加载rJava和xlsxjars包:

> library(rJava)
> library(xlsxjars)
Run Code Online (Sandbox Code Playgroud)

尝试加载xlsx包失败:

> library(xlsx)
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 : .onLoad failed in loadNamespace() for 'xlsx', details:
  call: .jinit()
  error: JNI_GetCreatedJavaVMs returned -1
Error: package or namespace load failed for ‘xlsx’
Run Code Online (Sandbox Code Playgroud)

R配置:

Matts-MacBook-Pro:~ matt$ R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 1.8.0_65
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_65.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.8.0_65.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_65.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.8.0_65.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.8.0_65.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
Run Code Online (Sandbox Code Playgroud)

San*_*yIV 59

不幸的是,这些符号链接技巧并没有帮助我.但是,我在stackoverflow上发现了类似的问题!(在其他地方;))这个通过以下方式为我工作:

  1. 在终端中输入以下内容以正确重新链接Java:

    sudo R CMD javareconf
    
    Run Code Online (Sandbox Code Playgroud)
  2. 回到R(或RStudio)从源代码安装rJava包:

    install.packages("rJava",type='source')
    
    Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

  • 之后我必须这样做才能工作:http://stackoverflow.com/questions/30738974/rjava-load-error-in-rstudio-r-after-upgrading-to-osx-yosemite (8认同)

小智 13

我也有加载openNLP,xlsx,RWeka等软件包的问题,​​并得到了和你一样的错误信息.但最后这个命令在OS X 10.11.3上对我有用: sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

  • `xlsx`在10.12 Sierra没有为我工作.如果我运行该命令它返回`ln:/usr/local/lib/libjvm.dylib:文件存在`但我仍然收到错误 (2认同)

小智 1

基本上,只需按照此处描述的操作即可: https://oliverdowling.com.au/2015/10/09/oracles-jre-8-on-mac-os-x-el-capitan/

简短版本:来自 Oracle 的 d/l Java JRE 作为 tar 文件 http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

然后将其放入您的终端(对于 sudo,需要您的密码):

cd ~/Downloads
tar -xzf `ls -1r jre-*-macosx-x64.tar.gz | head -1`
cd `ls -1rd jre*/ | head -1`
defaults write `pwd`/Contents/Info.plist JavaVM -dict-add 'JVMCapabilities' '<array><string>JNI</string><string>BundledApp</string><string>CommandLine</string></array>'
plutil -convert xml1 Contents/Info.plist
sudo mv `pwd` /Library/Java/JavaVirtualMachines/
mkdir -p Contents/Home/bundle/Libraries
cd Contents/Home/bundle/Libraries
ln -s ../../lib/server/libjvm.dylib libserver.dylib
Run Code Online (Sandbox Code Playgroud)

在我的 OS X 10.11 上运行良好

  • 对此要非常非常小心——“sudo mv `pwd` /Library/Java/JavaVirtualMachines”行会将 `pwd` 中的所有内容移动到该 Java 文件夹... (6认同)
  • 所以我这样做了......当然,它使我的计算机崩溃了,将我的所有文件移动到 JVM 文件夹中。我该如何“撤消”它?警告所有其他人:不要这样做! (4认同)