Niels Tolstrup
Niels Tolstrup

Reputation: 467

How to call/use MRI Ruby from Java?

I want to call Ruby methods from a Java environment. I have tried these four solutions:

  1. Use JRuby. This would be excellent because it runs everything in the Java virtual machine. However I have experienced some critical (unacceptable) performance issues:
    • JRuby does currently not work with my C extensions.
    • Fork calls from Ruby, do not behave stable when running in the Java virtual machine.
    • The code runs slower in JRuby than in MRI Ruby.
  2. Use ROR. Bypass Java all together by providing webservices via Ruby on Rails. This works but breaks the companies IT policy of using Java webservices only, it also forces either the IT department (Java and webservice developers) or the R&D department (Ruby and C developers) to work outside there domain.
  3. Use Java system calls. We can call stand alone Ruby programs with Java system calls and parse input and output data via XML files. This works, but the overhead of starting new processes and handling XML files is a performance issue.
  4. Use RJB. Ruby Java Bridge allows me to call Java from Ruby, but that is the reverse of what I need.

Is there a method to call MRI Ruby from Java, without any of the above described issues?

Upvotes: 1

Views: 588

Answers (1)

Jörg W Mittag
Jörg W Mittag

Reputation: 369448

You could make #3 more efficient by

  • not starting processes, instead use a long-running daemon process
  • not communicating via files but via pipes
  • using something more efficient than XML, like Protocol Buffers

But in general, I don't see any option you missed. Sorry.

Upvotes: 1

Related Questions