views:

103

answers:

4

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?

+2  A: 

Mostly I'd say no because of complexity. Although it's subjective, I'd personally rather take the time to re-write it anyway--you can make improvements and when you're done, you'll understand it better.

Bill K
I agree that, if possible, porting it to java would be wonderful. However, because of time constraints, the alternative I'll likely use is to just run it as a web service.
Todd R
+2  A: 

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.

Stuart Sierra
+1  A: 

One option you might consider is splitting your application into two pieces, which interact using either something like pipes/files (or simply stdin and stdout) or some sort of an RPC mechanism. Whether an approach like this makes sense really depends on what the Ruby library does - creating the interface between the two applications might be more complex than actually reimplementing the stuff in Java.

psyho
+1  A: 

I've reused Java code from JRuby, I don't see why this can't go both ways.

Another thought, can you run the Ruby code and then just tack on a web service or set of web services to call from the Java app? Sinatra makes it ridiculously simple to write a web service wrapper for ruby code. And Java has no shortage of tools to call Web Services.

sal