Arun Agrawal's Blog

Ruby on Rails Developer

Rails3 Application With Jruby

If you are living on edge and you are using Rails3 then you need follow this. Rails3 With JRuby   Hi All, Recently i have started a Rails3 application which will use Jruby. I have gone through some of the steps for that application up and running. If you are using RVM then it’s easy to install Jruby. In the latest RVM version Jruby-1.6.0 is the default one. So my recommendation is first update the RVM itself then install Jruby. To update RVM and get the Jruby-1.6.0 installed
rvm update 
# But if you are already on the latest RVM then you will get message the "rvm update has been removed".

#To install Jruby

rvm install jruby
After installing Jruby you need to switch your environment to Jruby
 
rvm use jruby
#Using /Users/arunagw/.rvm/gems/jruby-1.6.0
Can check by using
~~>jruby -v                                                                                                                                                                          
jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [darwin-x86_64-java]
~~>ruby -v                                                                                                                                                                           
jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [darwin-x86_64-java]
Now you are ready to play with Jruby stuff. You can do some basic stuff like irb to test things
irb
#IRB will also work
jirb
# JIRB will also work
Time to install Rails in Jruby environment
gem install rails 

#Will also work

jruby -S gem install rails
All set. Create your Rails application.
rails new my_app
Above command will create a rails application but not useful for Jruby platform. For all setting just run
rails new my_app -m http://jruby.org/rails3.rb
This will do all setup for you for a rails3 app in Jruby. You may need to change/update your Gemfile for your gems. Problems i faced. rake db:create will give you an error if you are using Mysql with Jruby.
uninitialized constant Mysql::Error
Here is the ticket information about this. Solution for this problem right now is to create database manually. After that all will work. No more hurdles i found. If you got in any problem let me know. We will try to solve that together. Links may be useful to find stuff 1. Jruby Activerecord adaptor. 2. My Sample Application 3. RVM —– Arun