问题
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