Search code examples
javarubyjrubypolyglot

Should I try to reuse Ruby code in a Java project?


I'd rather not "reinvent the wheel" and I've found a Ruby project that provides functionality I need in my Java app (there is no preexisting Java project that does what I need - trust me, I've looked). So, best case scenario, I am able to run the Ruby code from my Java code (ala JSR223).

However, this Ruby project depends on having several gems installed. I'm not at all interested in converting the entire Java app into a JRuby app, but I'd like to be able to leverage this project. Is there an easy way to load the code from a gem into a ScriptEngine, or am I just asking for headaches?


Solution

  • JRuby is a solid platform and integrates well with Java. But Rubygems do not integrate so well with Java build tools.

    If any of the gems include native C code, then forget it, you can't use them from JRuby.

    If all the gems (and all their dependencies) are pure Ruby, it is technically possible to use them from JRuby, but you will have headaches getting them packaged in JARs so that the JRuby runtime can find them.