Eclipse无法找到我安装的Ruby宝石(JRuby)

时间:2015-11-11 12:42:45

标签: java ruby eclipse gem

所以,我试图在JRuby的帮助下在我的java代码中使用我的ruby脚本。但是有一个问题,eclipse无法使用我安装的宝石。出于测试目的,我一直试图运行一段需要" nokogiri" ruby gem,我已安装。当我尝试运行java代码时,我得到的是:

LoadError: no such file to load -- nokogiri
  require at org/jruby/RubyKernel.java:939
    <top> at /home/amng/workspace/scripts/xx/x/getMSPatches:4
Exception in thread "main" org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- nokogiri
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1307)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1352)
at jobs.Teste.run(Teste.java:17)
at jobs.Teste.main(Teste.java:11)

引起:org.jruby.exceptions.RaiseException:(LoadError)没有要加载的文件 - nokogiri     在org.jruby.RubyKernel.require(org / jruby / RubyKernel.java:939)     在RUBY。(/ home / amng / workspace / scripts / myPrecious / MSPatches / getMSPatches:4)

我从网站下载了jruby.jar并添加到项目的构建路径中。我还使用Dynamic Languages Toolkit(DLTK)插件将eclipse指向JRuby二进制文件。我该怎么做才能确保eclipse可以使用我安装的宝石?

编辑:我的java代码:

import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.PathType;

public class Main {

    public static void main(String[] args) {
        ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
        Object result = ruby.runScriptlet(PathType.ABSOLUTE, "/home/amng/workspace/scripts/myPrecious/MSPatches/getMSPatches");
        System.out.println(result);
}

}

我的(工作)ruby代码(getMSPatches)的前两行是:

# encoding: UTF-8
require 'nokogiri'

1 个答案:

答案 0 :(得分:0)

尝试设置jruby主目录

ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
ruby.setHomeDirectory("/jruby-9.0.5.0");   

这解决了我的问题。