我可以加载rJava和xlsxjars包,但是当我执行库(xlsx)时,我得到了“无法加载JVM”。以下是我的详细信息。
操作系统版本:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.11
BuildVersion: 15A284
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)
Java Path:
$ which java
/usr/bin/java
Java Home:
$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
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)
我如何启动R:
$ LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio
成功加载rJava和xlsxjars包:
> library(rJava)
> library(xlsxjars)
尝试加载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’
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
答案 0 :(得分:59)
不幸的是,这些符号链接技巧对我没有帮助。但是,我在stackoverflow上发现了类似的问题! (还有哪里 ;)) 这个通过以下方式为我工作:
在终端中输入以下内容以正确重新链接Java:
sudo R CMD javareconf
回到R(或RStudio),从源代码安装rJava包:
install.packages("rJava",type='source')
希望,这有帮助!
答案 1 :(得分:13)
我在加载openNLP,xlsx,RWeka等软件包时遇到了问题,并得到了和你一样的错误信息。
但最后这个命令在OS X 10.11.3上对我有用:
sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
答案 2 :(得分:2)
在其中内置R xlsx软件包的Java版本中可能存在问题。一些旧软件需要安装Java 6 for OS X 10.11 El Capitan,OS X 10.10 Yosemite,OS X 10.9 Mavericks,OS X 10.8 Mountain Lion和OS X 10.7 Lion。 因此,您可以尝试在Apple网站上安装这个旧版本的Java(Java for OS X 2015-001),链接如下: https://support.apple.com/kb/DL1572?locale=pt_BR&viewlocale=en_US
并检查您是否有Java SE Development Kit 8.您可以在Oracle网站下载,链接如下: www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
我遇到了同样的问题并且下载了旧版本的Java解决了它..我希望这对你有帮助!
答案 3 :(得分:0)
基本上,只需执行此处描述的操作: https://oliverdowling.com.au/2015/10/09/oracles-jre-8-on-mac-os-x-el-capitan/
简短版本: d / l来自oracle的Java JRE作为tar文件 http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
然后把它放到你的终端(对于sudo,需要你的pw):
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
在我的OS X 10.11上正常工作
答案 4 :(得分:0)
对我来说,MacOS Catalina 10.15.7,就像安装当前的 JRE 和 JDK 软件一样简单(从 java.com 和 oracle.com 上的官方发行商网站下载为 .dmg 文件 - 没有任何从属关系!)。
我也(重新)安装了 rJava 包,但我觉得没有必要。实际上,我的计算机上根本没有安装 Java。
现在加载 xlsx
包。