如果我使用通过Intellij运行的Java模块,为什么Renjin示例会失败

时间:2019-08-06 19:44:54

标签: java java-module renjin

仅包含Renjin样本的项目按广告进行。

在添加module-info.java之前,启用模块化Java包管理。

然后ScriptEngine触发异常。
我正在IntelliJ最新版本中进行所有操作。 有解决办法吗?

package tryrenjin;
import javax.script.ScriptEngine;
import org.renjin.script.*;


    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();
            engine.eval("df <- data.frame(x=1:10, y=(1:10)+rnorm(n=10))");
            engine.eval("print(df)");
            engine.eval("print(lm(y ~ x, df))");
        }
    }
    <repositories>
        <repository>
            <id>bedatadriven</id>
            <name>bedatadriven public repo</name>
            <url>https://nexus.bedatadriven.com/content/groups/public/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.renjin</groupId>
            <artifactId>renjin-script-engine</artifactId>
            <version>3.5-beta64</version>
        </dependency>
    </dependencies>
module tryrenjin {
    requires java.scripting;
    requires renjin.script.engine;
}

没有模块信息,它可以工作:

      x     y    
 [1,]  1    0.347
 [2,]  2    2.006
 [3,]  3    4.285
 [4,]  4    4.033
 [5,]  5    4.152
 [6,]  6    7.243
 [7,]  7    7.001
 [8,]  8    6.846
 [9,]  9    9.487
[10,] 10    9.328

Call:
lm(formula = y ~ x, data = df)

Coefficients:
(Intercept) x          
0.206       0.958      

使用module-info,java生成

Exception in thread "main" java.lang.RuntimeException: org.renjin.eval.EvalException: Could not load package org.renjin:methods
    at renjin.core@3.5-beta64/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:181)
    at renjin.script.engine@3.5-beta64/org.renjin.script.RenjinScriptEngineFactory.getScriptEngine(RenjinScriptEngineFactory.java:110)
    at tryrenjin/tryrenjin.TryRenjin.main(TryRenjin.java:13)
Caused by: org.renjin.eval.EvalException: Could not load package org.renjin:methods
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:154)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:130)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.NamespaceRegistry.getNamespace(NamespaceRegistry.java:114)
    at renjin.core@3.5-beta64/org.renjin.primitives.packaging.Packages.library(Packages.java:39)
    at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.doApply(R$primitive$library.java:68)
    at renjin.core@3.5-beta64/org.renjin.primitives.R$primitive$library.applyPromised(R$primitive$library.java:33)
    at renjin.core@3.5-beta64/org.renjin.sexp.BuiltinFunction.apply(BuiltinFunction.java:100)
    at renjin.core@3.5-beta64/org.renjin.primitives.special.InternalFunction.apply(InternalFunction.java:46)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.primitives.special.BeginFunction.apply(BeginFunction.java:39)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.sexp.Closure.applyPromised(Closure.java:200)
    at renjin.core@3.5-beta64/org.renjin.sexp.Closure.apply(Closure.java:133)
    at renjin.core@3.5-beta64/org.renjin.sexp.FunctionCall.eval(FunctionCall.java:80)
    at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:280)
    at renjin.core@3.5-beta64/org.renjin.eval.Context.evaluate(Context.java:209)
    at renjin.core@3.5-beta64/org.renjin.eval.SessionBuilder.build(SessionBuilder.java:176)
    ... 2 more

0 个答案:

没有答案