Friday, September 21, 2007

Railing on JBoss

I recently successfully deployed a Ruby on Rails app running on jruby that uses ActiveRecord-JDBC adapter to talk to Oracle 10g database to run on JBoss 4.2.1. I used warbler plugin from Nick Seiger to convert the rails app to war file. I basically followed the instructions at this article about warbler (http://blog.nicksieger.com/articles/2007/09/04/warbler-a-little-birdie-to-introduce-your-rails-app-to-java) and this one on using warbler with JBoss http://www.advogato.org/person/johnnyb/. Warbler makes it very easy to convert a rails app into a war file.


There were a few quirks during this process which are listed below and hopefully these will be helpful to those trying to do the same. Theoretically this should work on any J2EE compliant app server or even Servlet containers.

  • I had to uncomment the following line in warble.rb (warbler config file)
#config.gems = ["ActiveRecord-JDBC", "jruby-openssl"]


and change it to


config.gems = ["rails", "ActiveRecord-JDBC"]


This packages rails and ActiveRecord-JDBC gems in the war file.
  • To use ActiveRecord-JDBC adapter you need to add the following code to environment.rb file

if RUBY_PLATFORM =~ /java/

require 'rubygems'

gem 'ActiveRecord-JDBC

require 'jdbc_adapter'

end

You need to be careful about where in that file you add these lines. They must be added before the line


Rails::Initializer.run do |config|

  • This one should be obvious but you need to add the jdbc driver jar to JBoss lib folder. Since I used the default configuration in Jboss I added it to C:\opt\jboss-4.2.1.GA\server\default\lib folder.