About running .class files generated by JRuby

半腔热情 提交于 2019-12-25 03:05:12

问题


Have a Ruby script,

print "HELLO"

If you use

jrubyc script.rb

You get a .class file.

How do I execute this in my Java program? (so that it outputs "HELLO" to the console). I am using JRuby's complete JAR.


回答1:


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'");

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)



来源:https://stackoverflow.com/questions/23718436/about-running-class-files-generated-by-jruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!