jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot™ 64-Bit Server
VM 24.79-b02 on 1.7.0_79-b15 +jit [Windows 7-amd64]
Main program in Java, calling JRuby code via RedBridge Core. Java
classes are in a Jar-File.
This setup works, as long I don’t insist that the Ruby code is also
executed from within the Jar-File, instead of being searched inside the
file system.
First, here is the WORKING case:
// My main program (Jmain.java):
import vp.VP;
public class Jmain {
public static void main(String[] args){
System.out.println(“Jmain started”);
VP vp = new vp.VP();
System.out.println(“vp instance created”);
vp.run();
System.out.println(“Jmain terminating”);
}
}
// My VP class (VP.java):
package vp;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.RubyObject;
import org.jruby.embed.ScriptingContainer;
import org.jruby.embed.LocalContextScope;
import java.util.*;
public class VP {
private ScriptingContainer container;
public VP() {
container = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
}
public void run() {
RubyObject asahi =
(RubyObject)container.runScriptlet(org.jruby.embed.PathType.RELATIVE,“rbsrc/bridge.rb”);
System.out.println(“scriptlet executed”);
}
}
My Ruby program rbsrc/bridge.rb
puts “Entering bridge” # Just to see what’s going on
File.write(“out.txt”,“This file was created by bridge.rb\n”)
… rest of the code not shown
:: I put everything into a jar file, including the Ruby files
:: (although I don’t need them there yet).
jar cvfm jars\vp.jar … rbsrc
:: The program is executed like this:
java -cp c:\jruby-9.0.4.0\lib\jruby.jar;jars\vp.jar Jmain
I see the result of all the println statements, and the file out.txt is
created.
Now for the NON-WORKING case:
In the whole setting, I change ONLY ONE line: The invocation of
bridge.rb becomes
RubyObject asahi =
(RubyObject)container.runScriptlet(org.jruby.embed.PathType.CLASSPATH,“bridge.rb”);
That is, I replace RELATIVE by CLASSPATH, and drop the “rbsrc/”. When I
run this, I get no error message, I get the output of all the println
statements, BUT I don’t see the output of the ‘puts’ statement, nor is
the file out.txt created!
Note that bridge.rb seems to be loaded correctly (if I change bridge.rb
to a different name, I get an exception), but it doesn’t seem to be
executed.
How come?