[英]How to run an existing Ruby script in a Java project using JRuby?
I am trying to run an existing Ruby script in a Java project with JRuby. 我正在尝试使用JRuby在Java项目中运行现有的Ruby脚本。 All the examples I have found write a Ruby script on the fly and run it like so:
我发现的所有示例都是即时编写Ruby脚本并按如下方式运行它:
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet("puts 'hello world'");
However I would like to run an existing Ruby script. 但是我想运行一个现有的Ruby脚本。 Haven't had any luck.
还没有运气。 Here's what I've been trying:
这是我一直在尝试的方法:
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet("/path/to/file/test.rb");
My test.rb
file looks like: 我的
test.rb
文件看起来像:
#!/usr/bin/env jruby
puts "hi"
As you can see from the API docs , runScriptlet
has several forms; 从API文档中可以看到,
runScriptlet
具有多种形式。 if you want it to execute a file, it needs two parameters ; 如果要它执行文件,则需要两个参数 ; in your case,
就你而言
container.runScriptlet(PathType.ABSOLUTE, "/path/to/file/test.rb");
tl;dr: When in doubt, check the docs. tl; dr:如有疑问,请检查文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.