0

我正在尝试在 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)

知道有什么问题吗?

4

1 回答 1

-1

解决方案很难找到,它似乎与 Intellij Idea 相关联,它在类路径中添加了以下路径,导致测试失败:

C:\Users\theaterofthought\.IntelliJIdea12\config\plugins\ruby\rubystubs\rubystubs18

清除和重新创建 IDEA 项目有助于为我的测试工作获得一个新的启动器,而在 -classpath 参数中没有此路径。

于 2013-06-21T12:52:27.670 回答