Java R 接口 (JRI) 设置 [英] Java R Interface (JRI) Setup

查看:18
本文介绍了Java R 接口 (JRI) 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Java/R 接口(捆绑在 RrJava"包中),但我遇到了一些问题(尽管在这里和其他论坛上尝试了很多建议).

我运行的是 Windows 7、jdk1.7.0_05、Eclipse、R 2.15.2.这些都是 64 位安装.

我尝试让示例运行的步骤如下:

  1. 在 R GUI 中安装 rJava: install.packages('rJava') - 安装到 C:UsersUSERNAMEDocumentsRwin-library2.15 Java
  2. 设置环境变量:R_HOME = "C:Program FilesRR-2.15.2", 添加到 PATH = "C:Program FilesJavajdk1.7.0_05in";"C:Program FilesJavajdk1.7.0_05jreinserver";"C:Program FilesRR-2.15.2inx64";"C:UsersUSERNAMEDocumentsRwin-library2.15 Javajrix64"
  3. 在 Eclipse 中设置示例项目,设置 VM 参数:-Djava.library.path="C:UsersUSERNAMEDocumentsRwin-library2.15 Javajrix64"
  4. 重新启动 R 并使用命令加载 rJava:libraries('rJava')
  5. 运行示例程序,获得以下异常:

找不到 JRI 原生库!请确保 JRI 本地库位于 java.library.path 中列出的目录中.

java.lang.UnsatisfiedLinkError: C:UsersUSERNAMEDocumentsRwin-library2.15
Javajrix64jri.dll: 找不到依赖库在 java.lang.ClassLoader$NativeLibrary.load(Native Method)在 java.lang.ClassLoader.loadLibrary1(来源不明)在 java.lang.ClassLoader.loadLibrary0(来源不明)在 java.lang.ClassLoader.loadLibrary(来源不明)在 java.lang.Runtime.loadLibrary0(来源不明)在 java.lang.System.loadLibrary(来源不明)在 org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)在 test.JRITest.main(JRITest.java:64)

我已验证java.library.path"是否按预期设置,因为: System.out.println("JLP = " + System.getProperty("java.library.path"));输出正确的路径.

我认为 rJava 可能没有完全安装(已尝试重新安装),但我不确定如何检查.... Javajri"或其任何子目录中唯一的 JAR 是JRI.jar",示例目录似乎不完整.

有人对这里可能出现的问题有什么建议吗?

看来 JRI 网站 (

这是一个代码示例及其输出:

此示例取自:http://codophile.com/2015/04/15/how-to-integrate-r-with-java-using-rjava/

I am trying to setup the Java/R interface (bundled in the R "rJava" package), but I am having some trouble (despite trying many suggestions here and on other forums).

I am running Windows 7, jdk1.7.0_05, Eclipse, R 2.15.2. These are all 64 bit installations.

The steps I have followed to attempt to get the example running are as follows:

  1. Install rJava within the R GUI: install.packages('rJava') - installs to C:UsersUSERNAMEDocumentsRwin-library2.15 Java
  2. Setup environment variables: R_HOME = "C:Program FilesRR-2.15.2", additions to PATH = "C:Program FilesJavajdk1.7.0_05in";"C:Program FilesJavajdk1.7.0_05jreinserver";"C:Program FilesRR-2.15.2inx64";"C:UsersUSERNAMEDocumentsRwin-library2.15 Javajrix64"
  3. Setup example project in Eclipse, setting VM argument: -Djava.library.path="C:UsersUSERNAMEDocumentsRwin-library2.15 Javajrix64"
  4. Restart R and load rJava with command: libraries('rJava')
  5. Run the example program, obtaining the following exception:

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: C:UsersUSERNAMEDocumentsRwin-library2.15
Javajrix64jri.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(Unknown Source)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
    at test.JRITest.main(JRITest.java:64)

I have verified "java.library.path" is set as expected since: System.out.println("JLP = " + System.getProperty("java.library.path")); outputs the correct path.

I think rJava may not have installed fully (have tried reinstalling), but I'm not sure how to check this. The only JAR in "... Javajri" or any of its subdirectories is "JRI.jar" and the examples directory seems incomplete.

Does anyone have suggestions on what may be going wrong here?

It seems the JRI website (http://www.rforge.net/JRI/index.html) has been down today, not sure if anyone knows another source to download from (other than direct from CRAN).

Thanks.

解决方案

After reading a lot of posts and trying a lot of different solutions, it is finally working. I'm using Windows 7 64bits and I'll list the steps that I did to make it work properly.

  1. Install package rJava using R install.packages("rJava")
  2. Right-click on My Computer > Properties > Advanced System Settings > Environment Variables...
  3. Find Var PATH or CLASSPATH and Edit, add the following paths: C:Program FilesRR-3.4.0inx64;C:Users [User Name]DocumentsRwin-library3.4 Javajrix64
  4. Go to C:Program FilesRR-3.4.0inx64 and copy all .dll files (here they are: R.dll,Rblas.dll,Rgraphapp.dll,Riconv.dll,Rlapack.dll)
  5. Past them at C:Program FilesJavajdk1.8.0_144in
  6. When you create your java project, remeber to add the JRI.jar, JRIEngine.jar and Rengine.jar to your project build path. They are located at C:Users [User name]DocumentsRwin-library3.4 Javajri
  7. After doing all this, I was still getting an error, that was solved when I went to C:Users [User Name]DocumentsRwin-library3.4 Javajrix64 and copy the jri.dll and past inside my Java Project, like the following image:

Here is a code example and its output:

This example was retrieved from: http://codophile.com/2015/04/15/how-to-integrate-r-with-java-using-rjava/

这篇关于Java R 接口 (JRI) 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆