问题描述
是否有人设法让rJava 0.9-3使用Oracle Java 1.7在OS X 10.7.4上工作?
Is there anyone out there who has managed to get rJava 0.9-3 to work on OS X 10.7.4 with Oracle Java 1.7?
R version 2.15.2 (2012-10-26) -- "Trick or Treat" Platform
x86_64-apple-darwin9.8.0/x86_64 (64-bit)
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
我使用install.packages函数和命令行安装R 2.15.2安装了rJava 。我没有收到任何错误。
I've installed rJava using both the install.packages function and the command line install with R 2.15.2. I don't get any errors.
$ R CMD INSTALL rJava
* installing to library ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
* installing *binary* package ‘rJava’ ...
* DONE (rJava)
$
如果我使用Java首选项将1.7放在列表中,但保留1.6on,则rJava始终启动1.6 。
If I use Java Preferences to put 1.7 first on the list, but leave 1.6 "on", rJava always starts 1.6.
如果我使用Java首选项将1.7放在第一位并关闭1.6,则rJava执行此操作:
If I use Java Preferences to put 1.7 first and turn off 1.6, rJava does this:
> library(rJava)
> .jinit()
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
>
但是,使用系统函数,R本身可以找到Java 1.7。
However, using the system function, R by itself finds Java 1.7.
> system("java -version")
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
>
1.7需要/System/Library/Java/JavaConfig.plist中的特殊条目吗?
Does 1.7 need a special entry in /System/Library/Java/JavaConfig.plist ?
Versions目录是否需要针对1.7进行调整?很奇怪,Current转到A,最终得到1.7而CurrentJDK被映射到1.6
Does the Versions directory need tweaking for 1.7 ? It is weird that Current goes to A, which ends up with 1.7 while CurrentJDK is mapped to 1.6
$cd /System/Library/Frameworks/JavaVM.framework/Versions/
$ls -la
total 64
drwxr-xr-x 11 root wheel 374 Sep 26 10:10 .
drwxr-xr-x 11 root wheel 374 Nov 26 09:24 ..
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 26 10:09 1.6.0 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 Nov 26 09:24 A
lrwxr-xr-x 1 root wheel 1 Sep 26 10:09 Current -> A
lrwxr-xr-x 1 root wheel 59 Sep 26 10:09 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
即使使用R CMD javareconf使用直接指向1.7文件的路径或者/ usr / bin / java路径运行,rJava仍然无法找到或启动Java 1.7。
Even with R CMD javareconf run with the path pointing to the 1.7 files directly or to the /usr/bin/java paths, rJava still can't find or start Java 1.7.
1.7是否需要JAVA_LD_LIBRARY_PATH变量集?
Does 1.7 need the JAVA_LD_LIBRARY_PATH variable set?
Makeconf:JAVA = /usr/bin/java
Makeconf:JAVAC = /usr/bin/javac
Makeconf:JAVAH = /usr/bin/javah
Makeconf:JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre
Makeconf:JAVA_LD_LIBRARY_PATH =
Makeconf:JAVA_LIBS = -framework JavaVM
Makeconf:JAVA_CPPFLAGS = -I$(JAVA_HOME)/include
Makeconf:JAR = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/bin/jar
Makeconf:JAVA = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/bin/java
Makeconf:JAVAC = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/bin/javac
Makeconf:JAVAH = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/bin/javah
Makeconf:JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre
Makeconf:JAVA_LD_LIBRARY_PATH =
Makeconf:JAVA_LIBS = -framework JavaVM
Makeconf:JAVA_CPPFLAGS = -I$(JAVA_HOME)/include
感谢您的帮助
更新1:
我在stats-rosuda-devel列表中问了这个问题,并收到了Simon Urbanek的以下回复。我不认为Windows和Linux在需要从源代码编译Java 1.7时遇到同样的问题,因为我们在Windows和Linux上运行它并且不必编译rJava。一旦我有机会尝试这个,我会报告:
I asked this on the stats-rosuda-devel list and received the following response from Simon Urbanek. I don't think Windows and Linux have the same problems with needing compile from source for Java 1.7, since we're running this on Windows and Linux and didn't have to compile rJava. I'll report back once I have a chance to try this:
另外,Oracle Java 1.7不是一个框架,它是一个很大的混乱,
是实际上并不是专为OS X设计的,所以你必须手动将其设置为Linux上的
设置 - 这非常痛苦。还需要
覆盖...所以如果你真的想要走下兔子洞,这个
对我有用:
In addition, Oracle Java 1.7 is not a framework, it's a big mess that was not really designed for OS X, so you have to set it by hand to settings like on Linux - it's pretty painful. Also it requires overrides ... so if you really want to go down the rabbit hole, this is what worked for me:
JAVA_LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/server
JAVA_LIBS='-L/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre/lib/server -ljvm'
JAVA_CPPFLAGS='-I/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/include/darwin'
R64 CMD javareconf
然后从源代码安装rJava(R64 - >
install.packages(rJava,type ='source'))。请注意,它只有64位,
所以它只适用于64位R。
Then install rJava from sources (R64 -> install.packages("rJava",type='source')). Note that it's 64-bit only, so it will only work with 64-bit R.
推荐答案
这对我有用:
情况是我的Java目录配置不正确。
The situation is that my Java directories were not configured correctly.
1)首先运行: sudo R CMD javareconf
。它应该如下:
1) First run: sudo R CMD javareconf
. It should the following:
Java interpreter : /usr/bin/java
Java version : 1.7.0_40
Java home path : /Library/Java/JavaVirtualMachines/jdk1.7.0_40.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 progam
detected JNI cpp flags : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
llvm-gcc-4.2 -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c conftest.c -o conftest.o
llvm-gcc-4.2 -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.7.0_40.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_40.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.
2)在R中,运行: install.packages(rJava, type ='source')
。安装应该返回DONE(rJava)。请注意,我必须设置
2) In R, run: install.packages("rJava",type='source')
. Installation should returns DONE(rJava). Note that, I had to set
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
当我需要以root身份启动R时:sudo R.要以普通用户身份运行,请使用
when I need to start R as root: sudo R. To run as a normal user, use
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre
我没想到将上面的/ usr / bin / java *的符号链接设置为Java中的对应链接1.7(转而使用版本1.6)并从那里得到了所有的挫败感。链接应该是这样的:(看起来R中只需要java,javac,javah和jar)。
It happened to me that I did not set the symbolic links of the above /usr/bin/java* to the corresponding in Java 1.7 (directed to version 1.6 instead) and got all the frustration from there. Links should be like this: (it looks like only java, javac, javah, and jar are required in R).
$ ls -l /usr/bin/ja*
lrwxr-xr-x 1 root wheel 71 Oct 3 11:44 /usr/bin/jar -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/jar
lrwxr-xr-x 1 root wheel 77 Oct 3 12:14 /usr/bin/jarsigner -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/jarsigner
lrwxr-xr-x 1 root wheel 72 Oct 3 11:44 /usr/bin/java -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java
lrwxr-xr-x 1 root wheel 73 Oct 3 11:42 /usr/bin/javac -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/javac
lrwxr-xr-x 1 root wheel 75 Oct 3 12:15 /usr/bin/javadoc -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/javadoc
lrwxr-xr-x 1 root wheel 73 Oct 3 11:44 /usr/bin/javah -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/javah
lrwxr-xr-x 1 root wheel 73 Oct 3 12:15 /usr/bin/javap -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/javap
lrwxr-xr-x 1 root wheel 74 Oct 3 12:15 /usr/bin/javaws -> /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/javaws
这篇关于如何让rJava 0.9-3在Oracle Java 1.7上运行OS X 10.7.4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!