Friday, September 25, 2009

JRuby on Rails building with warbler

Here I will mention the steps to create a JRuby (v1.3.1) on Rails (v2.3.3) application and build the war file using Warbler (v0.9.13) gem and then deploy in the JBoss (4.2.3.GA).

See my previous blog Oracle with JRuby using activerecord-jdbc-adapter to install JRuby, Rails and activerecord-jdbc-adapter to

In real life we need to work with gems & plugins for that reason I will now install some gems and plugins. jruby-openssl is required because if you don't install it then you will get JRuby limited openssl loaded. gem install jruby-openssl for full support

- JRUBY_HOME\bin\jruby -S gem install jruby-openssl
- JRUBY_HOME\bin\jruby -S gem install mislav-will_paginate
- install wee_date_picker plugin. To see the installation instruction see http://github.com/pyrat/wee_date_picker

Now create a rails project and in the environment.rb file add followings:

#config all the gems used with this project
config.gem "activerecord-jdbc-adapter", :version => '0.8', :lib => 'jdbc_adapter'
config.gem "jruby-openssl", :version => "0.5.1", :lib => 'openssl'
config.gem 'mislav-will_paginate', :version => '~> 2.3.11', :lib => 'will_paginate', :source => 'http://gems.github.com'
I like to configure my rails app to use gems and rails that are in the vendor folder. To make all the used gems copied to vendor/gems folder execute following rake task:

RAILS_APP_HOME>JRUBY_HOME\bin\rake gems:unpack:dependencies
To freeze rails with my application execute following rake task:
RAILS_APP_HOME>JRUBY_HOME\bin\rake rails:freeze:gems

Now its time to think about building the war/ear file to deploy in JBoss. As I have already said to build the war file I use Warbler. To do that install the gem:

JRUBY_HOME\bin\jruby -S gem install warbler

Its convenient to have warbler as plugins in your application and to make the plugin use following command and then you will have the warbler plugin in your vendor/plugins folder:

JRUBY_HOME\bin\warble pluginize

To customize files, libraries, and gems included in the.war file, you'll need a config/warble.rb file. As you have already created the warble plugin you can execute following to create warble.rb file for you:

RAILS_APP_HOME>JRUBY_HOME\bin\jruby script/generate warble
Now its time to create the war file of your project. To do that execute following rake task:

RAILS_APP_HOME>JRUBY_HOME\bin\rake war
At this point everything should be done but in my case I faced couple of problems. If you face problem please see my next blog 'Problem with Warbler'

No comments: