代码之家  ›  专栏  ›  技术社区  ›  Ceilingfish

无法加载jrubyengine,因为找不到org.apache.bsf.util.bsfengineimpl

  •  0
  • Ceilingfish  · 技术社区  · 15 年前

    我尝试在自定义应用程序中使用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对象。

    2 回复  |  直到 15 年前
        1
  •  0
  •   matt b    15 年前
        2
  •  0
  •   Ceilingfish    15 年前

    原来我应该用 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);
            }
        }
    
    }