// https://mvnrepository.com/artifact/net.rforge/Rserve
compile group: 'net.rforge', name: 'Rserve', version: '0.6-8.1'
// https://mvnrepository.com/artifact/org.nuiton.thirdparty/JRI
compile group: 'org.nuiton.thirdparty', name: 'JRI', version: '0.9-9'
// https://mvnrepository.com/artifact/net.rforge/REngine
compile group: 'net.rforge', name: 'REngine', version: '0.6-8.1'
或者自己导入
JRIEngine.jar
JRI.jarREngine.jar
启动Rserver服务:
library(Rserve);
Rserve();
测试代码import org.rosuda.REngine.REXP;
import org.rosuda.REngine.Rserve.RConnection;
public class Test1 {
public static void main(String[] args) {
try {
RConnection c = new RConnection();
REXP x = c.eval("R.version.string");
System.out.println(x.asString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
输出结果:
连接成功!