About half a year ago, a newcomer said, "I want to run R from Java," and I wrote a memo when I responded. It was okay to kick the process, but there was a module called ** JRI ** called ** Java / R Interface **, so I decided to deal with it.
What is rJava?
rJava is a simple R-to-Java interface.
It is comparable to the .C/.Call C interface.
rJava provides a low-level bridge between R and Java (via JNI).
It allows to create objects, call methods and access fields of Java objects from R.
http://www.rforge.net/rJava/index.html
In short, it's an interface that calls R via JNI. Since JNI is used, it was a little troublesome to set the dll file.
I will drop JRI.jar.
Start the R GUI and execute the installation command.
install.packages('rJava')
This will download the JAR and DLL under C: \ Program Files \ R \ R-3.3.1 \ library \ rJava \
.
It seems that JAR version control suddenly becomes chaotic.
Only JRI.jar seems to be able to manage the repository.
Click here to use Gradle.
// https://mvnrepository.com/artifact/org.nuiton.thirdparty/JRI
compile group: 'org.nuiton.thirdparty', name: 'JRI', version: '0.9-6'
Click here to use Maven.
<dependency>
<groupId>org.nuiton.thirdparty</groupId>
<artifactId>JRI</artifactId>
<version>0.9-6</version>
</dependency>
… But I absolutely need the dll file included in rJava. It seems that it is necessary to take individual measures such as dropping it from the original site without hitting the command. http://www.rforge.net/rJava/files/
Get jri.dll
and set it.
Either of C: \ Program Files \ R \ R-3.3.1 \ library \ rJava \ jri
.
64bit is x64
, 32bit is ʻi386`.
This time, I deployed it in the folder directly under the execution. If you want to deploy it in a different folder, you need to put it in your PATH.
You have to do it through your PATH.
How to run Windows environment
set PATH=%PATH%;C:/Program Files/R/R-3.3.1/bin;C:/Program Files/R/R-3.3.1/bin/i386;C:\Program Files\R\R-3.3.1\library\rJava\jri\i386
java ^
-classpath "./classes;C:/Program Files/R/R-3.3.1/library/rJava/jri/JRI.jar" ^
example.MyTest
It worked without the settings below.
Unnecessary settings?
set R_DOC_DIR="C:/Program Files/R/R-3.3.1/doc"
set R_INCLUDE_DIR="C:/Program Files/R/R-3.3.1/include"
set R_SHARE_DIR="C:/Program Files/R/R-3.3.1/share"
Add JRI.jar to WEB-INF / lib (not necessary if managed by Maven or Gradle).
You also need to set the path for jri.dll. Green Run Button> Run Configuration> Arguments> VM Arguments
Runtime arguments
-Djava.library.path="C:\Program Files\R\R-3.3.1\library\rJava\jri\i386"
Add
I often get this error.
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:1864)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at example.MyTest(MyTest.java:11)
Don't forget to set the path of jri.dll.
If you break through the above, the following will appear.
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:\dll\jri.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at example.MyTest(MyTest.java:11)
Even if it is set, I get angry when the dll dependency is wrong. jri.dll depends on bin / i386 or bin / x86 dll, so don't forget to set it as well.
Recommended Posts