关于运行JRuby生成的.class文件 [英] About running .class files generated by JRuby
问题描述
拥有Ruby脚本,
print "HELLO"
如果您使用
jrubyc script.rb
您将获得一个.class文件.
You get a .class file.
如何在Java程序中执行此操作? (以便它向控制台输出"HELLO").我正在使用JRuby的完整JAR.
How do I execute this in my Java program? (so that it outputs "HELLO" to the console). I am using JRuby's complete JAR.
推荐答案
thus you've probably setup "embedded" (if not check-out answers such as this one) JRuby from Java e.g. (JSR 223 might be similar - just use ScriptEngine.eval
to run Ruby code) :
ScriptingContainer scriptContainer = new ScriptingContainer(LocalContextScope.CONCURRENT);
scriptContainer.runScriptlet("load 'script.class'");
简单地load
.class文件 script.class ,前提是它可以从class-path/work-dir解析(否则可能需要调整LOAD_PATH
-确实取决于您的Java环境/场景)
simply load
the .class file script.class assuming it can be resolved from the class-path / work-dir (otherwise might need to tune the LOAD_PATH
- really depends on your Java environment/scenario)
这篇关于关于运行JRuby生成的.class文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!