我正在尝试在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)
知道可能出现什么问题吗?
答案 0 :(得分:-1)
解决方案很难找到,它似乎与Intellij Idea相关联,它在类路径中添加了以下路径,使测试失败:
C:\Users\theaterofthought\.IntelliJIdea12\config\plugins\ruby\rubystubs\rubystubs18
清除并重新创建IDEA项目有助于在-classpath参数中为我的测试工作而没有此路径的新启动器。