0

我正在尝试在自定义应用程序中使用 JRuby,但我似乎无法加载该JRubyEngine对象。我的课程在功能上看起来与此类似:

public class ScriptEngine {

    private static ScriptEngine engine = new JRubyEngine();

    public void run(final String script, final Map<String,Object> input) {
        final Bindings context = engine.createBindings();

        context.putAll(input);

        try {
            engine.eval(script,context);
        } catch (ScriptException e) {
            log.error("Failed to execute script: "+getScript(),e);
        }
    }

}

然而,这在编译时失败了:

[javac] Compiling 486 source files to /workspace/myProject/build/src
[javac] /workspace/myProject/src/net/ceilingfish/ScriptEngine.java:31: cannot access org.apache.bsf.util.BSFEngineImpl
[javac] class file for org.apache.bsf.util.BSFEngineImpl not found
[javac]     private static ScriptEngine engine = new JRubyEngine();
[javac]                                          ^
[javac] 1 error

有人对我可以从哪里获得这门课有任何见解吗?或者,如果有更好的方法来实例化 JRubyEngine 对象。

4

2 回答 2

0

您可以从http://jakarta.apache.org/site/downloads/downloads_bsf.cgi下载 Apache BSF

于 2010-03-17T16:55:48.347 回答
0

原来我应该一直在使用JRubyScriptEnginenot JRubyEngine。例如

import com.sun.script.jruby.JRubyScriptEngine;
    .... other imports

public class ScriptEngine {

    private static ScriptEngine engine = new JRubyScriptEngine();

    public void run(final String script, final Map<String,Object> input) {
        final Bindings context = engine.createBindings();

        context.putAll(input);

        try {
            engine.eval(script,context);
        } catch (ScriptException e) {
            log.error("Failed to execute script: "+getScript(),e);
        }
    }

}
于 2010-03-17T17:01:12.723 回答