Tuesday, September 04, 2007

Ruby Java Bridge

Against better judgement.... I just wrote some not so portable ruby using RJB, ruby java bridge, rjb.rubyforge.org, first I made a jar that contained little java class that I wrote for some LDAP testing(I needed to use java because of some SSL certificates contained in JVM), then I wrote following ruby in small rails app that displays the mess in a web app, pretty cool:

require 'rjb'
Rjb::load('/Users/villem/rails/ldaptester/script/ldaptester.jar', [])
lr = Rjb::import('LDAPreader')
fetcher = lr.new
result = fetcher.goForIt(params[:ldapstring], params[:server])
render_text result

Both on Mac OS X and on CentOS I had some trouble install RJB gem, error kept saying:
checking for jni.h... no
*** ext/extconf.rb failed ***
there were 2 problems, JAVA_HOME needs to be set, on OS X JAVA_HOME is set by default, however there is no include dir under the default Java dir, so I created a symlinked folder called include that has jni.h etc in it. Second problem had to due with the fact that I didn't have gcc installed and error message about jni.h really led me astray.
Anyway on centOS I simply did
sudo yum install gcc
and this fixed the problem.

0 Comments:

Post a Comment

<< Home