2

仅使用 ruby​​ 运行相同的测试时,我获得了成功。当尝试使用 JRuby 从 java 运行相同的测试时,它找不到所需的文件,例如“watir-webdriver”、“rubygems”等。

红宝石文件:

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();
}
}
4

2 回答 2

0

通过手动下载成功包含 ruby​​gems 并包含路径: 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/rubygems-update-2.0.3/lib/");

于 2013-07-07T09:02:24.037 回答
0

我在使用通过 RVM 安装的 JRuby 时遇到了同样的错误。

JRuby 版本:

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

以下显示了正确的 gem 列表(执行捆绑后)

$ 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
于 2013-08-23T15:35:29.160 回答