我試圖在Java程序內執行R腳本,所有依賴項都使用Maven安裝,但問題仍然存在。Renjin IOException當加載包Rweka時,找不到函數'.jfield'
在我的研究中,我發現jfield是rJava提供的一個函數,但我不確定rJava(Renjin包)是否實現了它。
¿有沒有辦法檢查這個? ¿或者我錯過了什麼?
我的程序使用此庫,通過韌勁所有支持:
- rJava
- RWeka
- RWekajars
而且I'm使用betadriven公共回購槽Maven來安裝它們。 這裏it's主類:
package org.dfont.renjin;
import org.renjin.script.RenjinScriptEngineFactory;
import javax.script.ScriptEngine;
public class TryRenjin {
public static void main(String[] args) throws Exception {
// create a script engine manager:
RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
// create a Renjin engine:
ScriptEngine engine = factory.getScriptEngine();
// ... put your Java code here ...
if(engine == null) {
throw new RuntimeException("Renjin Script Engine not found on the classpath.");
}
else{
engine.eval(new java.io.FileReader("/home/dfont/renjinTest/pruebaCalculo.R"));
}
}
}
在這裏,我的pom.xml,
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dfont.renjin</groupId>
<artifactId>renjin</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>rJava</artifactId>
<version>0.9-8-renjin-5</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>RWekajars</artifactId>
<version>3.9.1-3-b3</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>RWeka</artifactId>
<version>0.4-34-b5</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>bedatadriven</id>
<name>bedatadriven public repo</name>
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>org.dfont.renjin.TryRenjin</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
第一行輸出,當我運行程序:
Exception in thread "main" org.renjin.eval.EvalException: IOException while loading package org.renjin.cran:RWeka: could not find function '.jfield'
在此先感謝!
你能顯示你的代碼嗎? – SilverNak
忘記把我的代碼之前,第一次noob,修復! – dFont