rjb: Java classes in Rails

Fernando Perez wrote:

Hi,

For those who might not be aware, rjb is a killer gem for using java classes inside your rails app (or any ruby code). Check it out at: http://rubyforge.org/projects/rjb/

I was able to successfully use it in one of my apps that required some code that is only available in java. And it's much nicer than having to compile a java app, then shell out using backticks, get back the return value from the java app, split the strings, etc.

Last update to rjb was in this month, so the gem seems to be well maintained by its author :slight_smile:   

+1

Been using this for a couple months for access to iText. Works great.

+1

Been using this for a couple months for access to iText. Works great.

Oh by the way, as a best practice, where would you put the following:

require 'rjb' Rjb::load() JavaClass = Rjb::import(...)

Currently only one of my model uses rjb, so I put at the top of the file outside the class declaration, but what if another model also needs rjb access, and I put another Rjb::load, would it load the jvm twice? Should I move it to a more common place like in an initializer?