0

I want to know what is the pros and cons of using Runtime to execute Ruby script from Java class over using a ruby-java bridge JRuby?

Example for runtime

Process process = Runtime.getRuntime().exec("ruby start.rb blue_button_example_data.txt");
    try {
        process.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return;
    }

example of jRuby http://dior.ics.muni.cz/~makub/ruby/

I am asking because I have a legacy Java system and we are making integration with a system that has ruby scripts and we are trying to reuse them instead of rewrite them in java. and we want to know which approach is best.

Thanks!

3
  • 1
    Go with jRuby, its written by Nutter. Single handedly the best ruby/java hacker I know of. blog.headius.com Commented Sep 18, 2012 at 11:18
  • 1
    calling jRuby is faster (no process creation), and jRuby itself is said to be faster than Ruby. Commented Sep 18, 2012 at 11:25
  • Thanks for answering so fast! The link I posted above about jRuby example, it is giving instruction how to install jruby-engine.jar but the links there are broken, can you please help me in finding the correct download link? Thanks! Commented Sep 18, 2012 at 11:28

1 Answer 1

1

As people mentioned, JRuby will probably be faster, but more importantly it will allow you to have a tighter integration with Java: you can call Java code from JRuby, and vice-versa. This can also allow for a smoother transition between Java and Ruby, as the infrastructure can remain the same (you can deploy Rails app in Java EE application servers), and developers can progressively switch between the two.

See the JRuby wiki for more details on the integration.

The only downside with JRuby is that some MRI gems cannot be used, as they use native code — though this is not something I have been blocked by recently.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering. What I am going to do is too simple, we have a ruby script that parse text file and return the data in json format. What we want is to execute the script from java on runtime and manipulate these data. Given this information, is it really worth to do all the installation of JRuby vs. using RunTime to execute ruby script directly considering that the script is rarely executed.
@AhmadAlkhawaja The “cost” of calling a ruby script from Java is adding an extra jar to your Java application, i.e. the JRuby jar (if you use Maven, it’s just a matter of adding an extra dependency). This “cost” is not only fairly low, it is offset by not having to worry about spawning a new process from the JVM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.