是否可以从Java中的ScriptEngineManager设置我的jruby的gem路径?问题是我使用的是压缩的jruby解释器(jruby-complete.jar)并且不可能使用预先安装的gem获得此包,所以我正在尝试使用ScriptEngineManager从Java运行jruby并重定向宝石的路径,我已经安装在我的硬盘上。
示例:
public class Main {
public static void main(String[] args) {
StringBuffer jruby = null;
ScriptEngine runtime = null;
try {
runtime = new ScriptEngineManager().getEngineByName("jruby");
jruby = new StringBuffer();
jruby.append("require 'ruby/Libraries.rb'");
jruby.append("\r\n");
jruby.append("if __FILE__ == $0");
jruby.append("\r\n");
jruby.append("\tzkan = ZKANWritter.new(\"");
jruby.append("G:/path/output.xls");
jruby.append("\",\"");
jruby.append("G:/path/kanban.txt");
jruby.append("\",\"//path/LT CUU.tab\")");
jruby.append("\r\n");
jruby.append("\tzkan.write(2)");
jruby.append("\r\n");
jruby.append("end");
runtime.eval(jruby.toString());
} catch (Exception ex) {
System.out.println("Error: " + ex.getMessage());
}
}
}
先谢谢
~EderQuiñones
答案 0 :(得分:2)
我刚刚设置了环境变量RUBYLIB& GEM_HOME以编程方式来自ruby:
ENV["RUBYLIB"] = "lib/libs"
ENV["GEM_HOME"] = "lib/gems"
require "library-1.rb"
...
require "library-n.rb"