I have a Ruby script that I would like to run when my Java program starts.
When you tell ScriptEngine to evaluate the code for the first time, it will take some time. I get the impression that the reason it's been taking so long is because you need to compile the code first, right?
I found that you can compile Ruby code and then evaluate it later. Evaluation itself is fast — the compilation part is slow. Here I compile:
jruby = new ScriptEngineManager().getEngineByName("jruby");
Compilable compilingEngine = (Compilable)jruby;
String code = "print 'HELLO!'";
CompiledScript script;
script = compilingEngine.compile(code);
This fragment takes some time. Later, when you rate it, that's fine.
So, I was wondering if it is possible to “save” this compiled code to a file, so in the future I will be able to “download” it and just execute it without compiling again.