Reputation: 539
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!
Upvotes: 0
Views: 3363
Reputation: 26743
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.
Upvotes: 1