无法加载 JRubyEngine,因为找不到 org.apache.bsf.util.BSFEngineImpl

发布于 2024-08-25 16:33:33 字数 1048 浏览 3 评论 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 对象。

I'm trying to use JRuby in a custom application, and I don't seem to be able to load the JRubyEngine object. My class looks like functionally similar to this:

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);
        }
    }

}

However this fails at compilation with the complaint:

[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

Does anyone have any insights on where I can get this class from? Or if there is a better way to be instantiating a JRubyEngine object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-09-01 16:33:33

事实证明我应该使用 JRubyScriptEngine 而不是 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);
        }
    }

}

Turns out I should have been using JRubyScriptEngine not JRubyEngine. e.g.

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);
        }
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文