当使用ruby运行相同的测试时,我获得了成功。当尝试使用JRuby从java运行相同的测试时,它找不到需要的文件,如“watir-webdriver”,“rubygems”等。
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 :(得分:0)
通过手动下载成功包括rubygems并包含thos路径: loadPaths.add( “/ USR /本地/ RVM /红宝石/ JRuby的1.7.4 / LIB /红宝石/宝石/共享/宝石”); loadPaths.add( “/ USR /本地/ RVM /红宝石/ JRuby的1.7.4 / LIB /红宝石/宝石/共享/宝石/的rubygems更新-2.0.3 / LIB /”);
答案 1 :(得分:0)
我使用通过RVM安装的JRuby遇到了同样的错误。
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