I am attempting to use a JRuby script from inside a Java program. I can
get the JRuby script engine to run, but after the script finishes, the
program just terminates. Here is some code.
import javax.script.*;
public class ScriptTest1 {
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName(“jruby”);
// Evaluate JRuby code from string.
try {
engine.eval("puts('Hello!')"); // first
System.out.println("Never seen");
engine.eval("t1 = Test.new 'Testy'"); // second
javax.swing.JOptionPane.showConfirmDialog(
null, "Sometimes gets here");
} catch (ScriptException exception) {
System.out.println("Got error: " + exception);
}
}
}
The Ruby script prints out the greeting, but the “Never seen” is never
seen, and the confirmation dialog never appears. However, if I comment
out the send engine.eval, then the dialog box DOES appear.
I have no idea what is going on; can anyone shed some light?
JRuby 1.5.2
Java 1.6.0.17
Netbeans 6.9.1
Windows XP SP3