Using a Ruby Gem in Java

I have not found much information on this topic, but I have a ruby gem
that I want to use in my java project. Is there an easy way to
accomplish this?

There’s a bit of trickery required, but it is possible.

The process I follows goes like this:

  • “Ungem” the gem; in other words, you want the lib/ files only.
  • Write a piece of Ruby code that provides Java signatures, as seen
    here: GeneratingJavaClasses · jruby/jruby Wiki · GitHub
  • Compile the class and put it (under its proper package structure)
    and the gem’s libraries into the same jar, perhaps with JRuby’s jar
    contents in there too (if you want this all in one jar). The lib/
    contents should be at the root of the jar, so they can be found for
    loading.
  • Use that jrubyc --javac compiled class as your entry point into the
    library.

Can you elaborate a bit on how your project is structured? Mostly
Java-based?

  • Charlie