6

I've a ruby application which I compiled into a jar using warbler. I'm able to run it as a standalone using a command like java -jar executable.jar. But I'm unable to figure out how I'd use this jar in Java code. Specifically, I want to create objects of my Ruby classes in the Java code and then call the methods.

arrac
  • 597
  • 1
  • 5
  • 15

1 Answers1

2

You can start it with ProcessBuilder:

ProcessBuilder processBuilder = new ProcessBuilder("/path/to/java", "-jar", "executable.jar");
processBuilder.directory(new File("preferred/working/directory"));
Process process = processBuilder.start();

or another way if you use Windows:

Runtime.getRuntime().exec("cmd /c start executable.jar");
MikroDel
  • 6,705
  • 7
  • 39
  • 74
  • I specifically wanted to create objects of my Ruby classes in the java code. Technically, Java objects of my Ruby classes if I may say so. The Ruby classes use Ruby gems which I've packaged as a jar (executable.jar). I've edited the original question to reflect this. – arrac Jul 10 '13 at 08:22
  • 1
    @arrac - maybe it is better for you to use https://github.com/jruby/jruby/wiki/StandaloneJarsAndClasses - to generate Java classes from Ruby? – MikroDel Jul 10 '13 at 08:55