java 如何在 OSX 上配置 rJava 以选择正确的 JVM——.jinit() 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34971966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does one configure rJava on OSX to select the right JVM -- .jinit() failing
提问by user1172468
I installed rJava by calling install.packages("rJava") -- no problems seen
我通过调用 install.packages("rJava") 安装了 rJava——没有发现任何问题
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:
我正在运行 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:
我安装了以下 Sun JDK:
$ ls /Library/Java/JavaVirtualMachines/
jdk1.7.0_79.jdk jdk1.8.0_65.jdk
Which Java is on my PATH:
哪个 Java 在我的 PATH 中:
$ which java
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home//bin/Java
I also have JavaHome defined as:
我也将 JavaHome 定义为:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/
回答by Jonathan Hodge
The answer at https://stackoverflow.com/a/36045290/4351357helped resolve this issue for me on MacOS Sierra Version 10.12. In particular, it provided the code in command 1, below.
https://stackoverflow.com/a/36045290/4351357 上的答案帮助我在 MacOS Sierra 版本 10.12 上解决了这个问题。特别是,它在下面的命令 1 中提供了代码。
The three Terminal commands I used are:
我使用的三个终端命令是:
sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
sudo R CMD javareconf
install.packages("rJava",type='source')
sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
sudo R CMD javareconf
install.packages("rJava",type='source')
回答by Tim Child
This solution Cannot load R xlsx package on Mac OS 10.11
此解决方案 无法在 Mac OS 10.11 上加载 R xlsx 包
sudo R CMD javareconf
install.packages("rJava",type='source')
Worked for me
对我来说有效
回答by mtbiker-s
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/
在尝试在 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.
我一直收到同样的错误。我试图按照 Tim Child 的建议进行安装。我注意到的是,我的 R Studio 版本(版本 0.99.896 )一直抱怨为 OSX 安装 1.6 Legacy Java。
I installed the legacy Java from the website https://support.apple.com/kb/DL1572?locale=en_US
我从网站https://support.apple.com/kb/DL1572?locale=en_US安装了旧版 Java
Then ran a simpler test in R Studio.
然后在 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.
很高兴看到我运行了另一个测试(然后是让我走上这条道路的那个)。我仍然无法设置最新的 Java 版本。
I did one more re-install of the package rJava
我又重新安装了 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 :)
一切正常,目前使用 Java 1.6 版本,但至少我可以完成一些工作。希望有些人遇到更好的修复:)
回答by BioinfoNerd
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
我在这个问题上挣扎了几个小时。这里有一个非常好的线程,有一些关于 rJava 的背景: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
以下步骤最终对我有用:
(1)升级到最新的 JDK
(2)在我的 ~/.bash_profile 中设置以下环境变量:
export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_CPPFLAGS=$(/ usr/libexec/java_home)/include
(3) 以 root 身份从源代码重新安装 rJava:
sudo R CMD INSTALL rJava_0.9-8.tar.gz
(4) 以 root 身份重新配置 Java:
sudo R CMD javareconf
Then I could properly install other libraries that depended on the correct configuration of rJava.
然后我可以正确安装依赖于 rJava 正确配置的其他库。