R/RStudio、优胜美地和 Java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28796108/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:12:03  来源:igfitidea点击:

R/RStudio, Yosemite, and Java

javarrstudioosx-yosemite

提问by Eric Green

I upgraded to OSX Yosemite yesterday. When I run library(xlsx)in RStudio, the program crashes and I get the message: "To open 'RStudio' you need to install the legacy Java SE 6 runtime." I get the same result and message about opening Rwhen I run library(xlsx)in R.

我昨天升级到 OSX Yosemite。当我运行library(xlsx)RStudio,程序崩溃并收到消息:“要打开‘RStudio’,您需要安装旧版 Java SE 6 运行时。” 我得到有关打开相同的结果和消息R当我运行library(xlsx)R

Here are my details:

这是我的详细信息:

Mac Yosemite, Version 10.10.2
R version 3.1.2 (2014-10-31) 
Platform: x86_64-apple-darwin13.4.0 (64-bit)

I have Java Version 8 update 31. I ran java -versionand got this message: "No Java runtime present, requesting install." So I installed Java SE Development Kit 8u31. Now:

我有 Java 版本 8 更新 31。我运行java -version并收到以下消息:“不存在 Java 运行时,请求安装。” 所以我安装了Java SE Development Kit 8u31。现在:

java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

This did not do the trick because running library(xlsx)still crashes the program and throws a warning. Do I need to somehow roll back to Java SE 6 runtime, or is there a way to use the latest version I have installed?

这并没有奏效,因为运行library(xlsx)仍然会使程序崩溃并发出警告。我是否需要以某种方式回滚到 Java SE 6 运行时,或者有没有办法使用我安装的最新版本?

This SO postseems to be related, but I am not clear about the propsoed solution to install Java 6. The answer links to an apple support pagethat seems out of date.

这个 SO 帖子似乎是相关的,但我不清楚安装 Java 6 的建议解决方案。答案链接到一个似乎过时的苹果支持页面

I'm not familiar with Java, so I could use some advice.

我不熟悉 Java,所以我可以使用一些建议。

采纳答案by Eric Green

instead the java you have installed download this one

而不是你安装的java下载这个

https://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US

https://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US

after installing it, your problem will be solved

安装后,你的问题就解决了

回答by awfulHack

This worked for me: setting two env variables in ~/.profile

这对我有用:在 ~/.profile 中设置两个环境变量

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/server

I can install the rJava and xlsx packages in Rstudio as such. Admittedly, though, it took hours of tinkering around (mindlessly) to get it just right.

我可以在 Rstudio 中安装 rJava 和 xlsx 包。不可否认,虽然,花了几个小时(无意识地)修补才能使它恰到好处。

回答by Dr. Arun

I was able to get rJava loaded with Java 8. It looks like this is a problem with RStudio not passing certain environment variables into its rsession from Yosemite. Hopefully they'll fix it soon, but in the mean time you can pass the environment variable yourself in a terminal. Run this:

我能够使用 Java 8 加载 rJava。看起来这是 RStudio 没有将某些环境变量从优胜美地传递到其 rsession 的问题。希望他们能尽快修复它,但与此同时,您可以自己在终端中传递环境变量。运行这个:

$LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio

$LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio

Basically what you're doing here is running the java_home executable, which returns your Java path, and then appending the jre/lib/server directory. This gets assigned to LD_LIBRARY_PATH, which is what RStudio needs to correctly.

基本上你在这里做的是运行 java_home 可执行文件,它返回你的 Java 路径,然后附加 jre/lib/server 目录。这被分配给 LD_LIBRARY_PATH,这是 RStudio 正确需要的。