簡體   English   中英

Eclipse找不到我已安裝的Ruby gem(JRuby)

[英]Eclipse can't find my installed Ruby gems (JRuby)

因此,我試圖在JRuby的幫助下在Java代碼中使用我的ruby腳本。 但是有一個問題,蝕無法使用我安裝的寶石。 為了進行測試,我一直在嘗試運行一段需要安裝“ 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)沒有要加載的文件-RUBY上的org.jruby.RubyKernel.require(org / jruby / RubyKernel.java:939)上的nokogiri。(/ home / amng /工作區/腳本/ myPrecious / MSPatches / getMSPatches:4)

我從網站上下載了jruby.jar,並將其添加到項目的構建路徑中。 我還使用動態語言工具包(DLTK)插件將日食指向了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'

嘗試設置jruby主目錄

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

這為我解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM