Rjb: Java classes in Rails

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:

Fernando P. wrote:

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.


Jack C.
[email protected]

+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?

While I’m at it, if you use textmate, can you run unit tests that use
rjb?

When I run the tests from console they pass, but from textmate,
interpreter tells me that the java method calls I make don’t exist, so I
guess rjb or jvm is not properly loaded.