BSF, JRuby and ActiveRecord

3 10 2006

I’ve had some success on my current project. The other day I wrote a Ruby script that runs in JRuby and updates SQLServer using a JDBC connection. I used ActiveRecord and ActiveRecord – JDBC (both very hot). Tonight I embedded JRuby in a Java process using BSF and was still able to successfully execute the script. I discovered that, once the ActiveRecord stuff initializes during the first execution, each subsequent execution runs well. I figured that would be the case, but it’s always nice to have the proof.

Next, I’d like to extend the ActiveRecord – JDBC so that it will retrieve connections from a JNDI Datasource. If anyone’s already done some work in that direction, I’d be interested in hearing about it.




4 responses

3 12 2006


Looks like you have some experience with Java and Activerecord/Jruby and I am experiencing some pb to run jruby from java… to be more precise I want to write into a database but am getting:
org.jruby.exceptions.RaiseException: undefined method `cattr_accessor’ for ActiveRecord::Base:Class


runJRuby.evalScript(“require \’active_record/connection_adapters/jdbc_adapter\'”);

Hope you can help. Thanx in advance.


3 12 2006

Make sure that you require ‘active_record’ before using ActiveRecord::Base.

4 12 2006

Thanx I will trie that.
One other question… JRuby is new for me, do you know nice tutorials that explain how to call JRuby from Java? I only found tutorial to do it the other way around.

4 12 2006

Here’s how you embed JRuby using BSF:

After that, you call it like you would any other BSF enabled scripting language.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: