tags:

views:

12

answers:

2

Hi, 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.

A: 

You can download Apache BSF from http://jakarta.apache.org/site/downloads/downloads_bsf.cgi

matt b
I've already got it downloaded. I used Apache Ivy to retrieve it
Ceilingfish
A: 

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

}
Ceilingfish