在 Windows 上设置 Java R 接口 (JRI)
Setting up Java R Interface (JRI) on Windows
我已经按照网络上的指南进行操作并查看了有关 Whosebug 的问题,但我仍然无法在 Windows 上设置 JRI。
以下是我采取的步骤:
1) 安装 R
2) 在R中执行install.packages("rJava")
安装rJava
3) 创建一个 R_HOME
系统变量,值为 C:\Program Files\R\R-3.1.2
4) 将以下内容添加到我的 PATH
变量中:C:\Program Files\R\R-3.1.2\bin\x64;C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri\x64
5) 在 IntelliJ
中添加了 JRI.jar(位于 C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri
)作为依赖项
6) 将 IntelliJ 中的 VM 选项设置为 -Djava.library.path=C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri\x64
7) 启动R并执行library("rJava")
8) 运行 我的程序来测试是否一切都已设置好
得到以下错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006c726096, pid=5860, tid=6932
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [R.dll+0x26096]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\USERNAME\Documents\Project\hs_err_pid5860.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
如果我删除 VM 选项以便未指定 java.library.path,则会收到以下错误:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: no jri in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at com.coagsm.cs.fyp.Test.<clinit>(Test.java:11)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
你是如何实例化Rengine的?
应该是这样的:
Rengine rengine = new Rengine(args, false, null);
其中,参数可能来自您的主要方法。
如果可行,请告诉我!
最近(2018)对我来说是这样做的:-
export R_HOME=$(R RHOME)
然后编译:-
String[] enginargs = {"--no-save"};
REngine engine = org.rosuda.REngine.JRI.JRIEngine.createEngine(enginargs, null, false);
try {
engine.parseAndEval("print(\"Hello from R\");");
}
catch(Exception e ) {
System.err.println("OOps:-" + e.getMessage());
}
finally {
engine.close();
}
然后当 运行 时 java 要么设置 LD_LIBRARY_PATH 包含 JRI
或者设置 -Djava.library.path 例如
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/R/site-library/rJava/jri/
或
java -Djava.library.path=/usr/local/lib/R/site-library/rJava/jri/ MyMainClass
我已经按照网络上的指南进行操作并查看了有关 Whosebug 的问题,但我仍然无法在 Windows 上设置 JRI。
以下是我采取的步骤:
1) 安装 R
2) 在R中执行install.packages("rJava")
安装rJava
3) 创建一个 R_HOME
系统变量,值为 C:\Program Files\R\R-3.1.2
4) 将以下内容添加到我的 PATH
变量中:C:\Program Files\R\R-3.1.2\bin\x64;C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri\x64
5) 在 IntelliJ
中添加了 JRI.jar(位于C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri
)作为依赖项
6) 将 IntelliJ 中的 VM 选项设置为 -Djava.library.path=C:\Users\USERNAME\Documents\R\win-library.1\rJava\jri\x64
7) 启动R并执行library("rJava")
8) 运行 我的程序来测试是否一切都已设置好
得到以下错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006c726096, pid=5860, tid=6932
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [R.dll+0x26096]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\USERNAME\Documents\Project\hs_err_pid5860.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
如果我删除 VM 选项以便未指定 java.library.path,则会收到以下错误:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: no jri in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at com.coagsm.cs.fyp.Test.<clinit>(Test.java:11)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
你是如何实例化Rengine的?
应该是这样的:
Rengine rengine = new Rengine(args, false, null);
其中,参数可能来自您的主要方法。
如果可行,请告诉我!
最近(2018)对我来说是这样做的:-
export R_HOME=$(R RHOME)
然后编译:-
String[] enginargs = {"--no-save"};
REngine engine = org.rosuda.REngine.JRI.JRIEngine.createEngine(enginargs, null, false);
try {
engine.parseAndEval("print(\"Hello from R\");");
}
catch(Exception e ) {
System.err.println("OOps:-" + e.getMessage());
}
finally {
engine.close();
}
然后当 运行 时 java 要么设置 LD_LIBRARY_PATH 包含 JRI 或者设置 -Djava.library.path 例如
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/R/site-library/rJava/jri/
或
java -Djava.library.path=/usr/local/lib/R/site-library/rJava/jri/ MyMainClass