2013-07-03 20 views
2

當使用紅寶石運行相同的測試只有我成功。當試圖使用JRuby運行從Java相同測試中沒有找到需要的文件,如「的Watir-webdriver的」,「RubyGems的」等使用JRuby無法運行單元測試,沒有這樣的文件加載 - ruby​​gems

Ruby的文件:

require "rubygems" 
require "watir-webdriver" 

puts "Hello!!! test finished" 

錯誤跟蹤:

LoadError: no such file to load -- rubygems 
    require at org/jruby/RubyKernel.java:1054 
    (root) at /home/Oras/workspace/OptifyTestSuiteRuby/automation-watir/tes.rb:2 
Exception in thread "main" org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- rubygems 
    at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133) 
    at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264) 
    at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1309) 
    at OptifyTest.com.Main.<init>(Main.java:18) 
    at OptifyTest.com.Main.main(Main.java:22) 
Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- rubygems 
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1054) 
    at RUBY.(root)(/home/Oras/workspace/OptifyTestSuiteRuby/automation-watir/tes.rb:2) 

Java文件:

import java.util.ArrayList; 
import java.util.List; 

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

public class Main { 
private final static String jrubyhome = "/home/Oras/workspace/OptifyTestSuiteRuby/automation- watir"; 
private final String filename = jrubyhome + "/tes.rb"; 

private Main() { 
    ScriptingContainer container = new ScriptingContainer(); 
    List<String> loadPaths = new ArrayList(); 
    loadPaths.add(jrubyhome); 
    container.setLoadPaths(loadPaths); 
    container.runScriptlet(PathType.ABSOLUTE, filename); 
} 

public static void main(String[] args) { 
    new Main(); 
} 
} 
+0

我試圖用loadPath.add播放一下,也許我沒有添加正確的路徑? – Oras

回答

0

成功,包括手動和下載的RubyGems包括thos路徑: loadPaths.add(「/ usr/local/rvm/rubies/jruby-1.7.4/lib/ruby​​/gems/shared/gems」); loadPaths.add(「/ usr/local/rvm/rubies/jruby-1.7.4/lib/ruby​​/gems/shared/gems/ruby​​gems-update-2.0.3/lib /」);

0

我遇到了使用JRuby通過RVM安裝的同樣的錯誤。

JRuby的版本:

$ jruby -v 
jruby 1.7.4 (1.9.3p392) [snip] 

下顯示正確的寶石列表(執行捆綁後)

$ jruby -Xdebug.scriptResolution=true -S gem list 

使用編譯我的應用程序:

$ jrubyc main.rb 

當我執行我爲jruby-complete jar添加類路徑,在這裏找到: http://repository.codehaus.org/org/jruby/jruby-complete/1.7.4/

$ java -cp .:./jruby-complete-1.7.4.jar main 
相關問題