从 ScriptEngineManager eval 方法设置 gem 路径
是否可以从 Java 中的 ScriptEngineManager 设置我的 jruby 的 gem 路径?问题是我正在使用压缩的 jruby 解释器 (jruby-complete.jar) 并且不可能使用预安装的 gems 获取此包,所以我尝试做的是使用 ScriptEngineManager 从 Java 运行 jruby 并重定向我在硬盘上安装的 gem 的路径。
示例:
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());
}
}
}
提前致谢
~ Eder Quiñones
Is it possible to set my jruby's gem path from the ScriptEngineManager in Java? The problem is that I'm using a compressed jruby interpreter (jruby-complete.jar) and it's not possible to get this package with pre-installed gems, so what I'm trying do is running jruby from Java using the ScriptEngineManager and redirect the gem's path to the ones that I have installed on my hard drive.
Example:
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());
}
}
}
Thanks in Advance
~ Eder Quiñones
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚设置了环境变量 RUBYLIB & GEM_HOME 以编程方式来自 ruby:
I've just set the environment variables RUBYLIB & GEM_HOME programmatically from ruby: