I’m getting some very strange behavior requiring the standard Ruby cgi
library running embedded in a Java program using RedBridge with JRuby
1.4.0.
This Java program will reproduce the problem:
import org.jruby.embed.ScriptingContainer;
public class EmbedTest {
public static void main(String[] args) {
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(“require ‘cgi’”);
container.runScriptlet(“require ‘hello’”);
}
}
‘hello.rb’ is an empty file in my classpath.
When run I get the following:
~% java EmbedTest
:1 warning: warning: variable $= is no longer effective :1: $! not set. (ArgumentError) Exception in thread "main" org.jruby.embed.EvalFailedException: $! not set. at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:116) at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:457) at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:450) at EmbedTest.main(EmbedTest.java:8) Caused by: org.jruby.exceptions.RaiseException: $! not set. at (unknown).new(:1) at (unknown).(unknown)(:1) If I get rid of the line requiring hello.rb I just get the first warning message about $= not being effective. So far only the 'cgi' require causes the problem. For example "require 'date'" doesn't cause any problems. From the command line I can do: jruby -e "require 'cgi'; require 'hello'" and it works just fine. It's only when I embed, and only when I make separate calls to runScriptlet that causes the problem. I tried LocalContext.SINGLETON, THREADSAFE and SINGLETHREAD all with the same results. Could this be a JRUby emebed / Redbridge bug of some sort? (This is a problem for me because I'm trying to embed a ruby program that uses ActiveRecord, which depends on ActiveSupport, which in turn requires 'cgi'. I can run my program from the command line using JRuby 1.4.0 just fine, but I can't embed it; I get the above error.) Steve