我正在尝试在 Java webapp 中使用 JRuby 1.7.4。这是我要运行的代码:
require 'strscan'
scanner = StringScanner.new("test\ntest\n")
scanner.bol?
这是使用以下 Java 代码执行的:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("jruby");
InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.rb");
InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"));
engine.eval(inputStreamReader);
不幸的是,它以这个例外结束:
NoMethodError: undefined method `bol?' for nil:NilClass
(root) at <script>:3
javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `bol?' for nil:NilClass
at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:104)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:121)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:146)
知道有什么问题吗?