Arun Agrawal’s Blog

Ruby on Rails Developer

Rails 3.0.10 and JRuby

Finally, The Rails is coming with template support with JRuby platform. We used to use “-m” option to generate new Rails Application for JRuby platform. Which is┬áno more need now. Just set your platform to JRuby and create a new Rails Application as you do normally and it will generate a Application which is ready to go. No more tweaks required..!! This pull request which get merged into Rails 3-0-stable branch and it’s shipped with Rails 3.0.10.rc1 and will come with Rails 3.0.10. This feature is also coming with Rails 3.1. Showing here some of the example which will create Rails Application for JRuby platform. I have tested this on JRuby 1.6.3 version.
rvm jruby-1.6.3
# Will set your environment for JRuby 1.6.3 version.
Time to create rails app. This will generate a rails app for JRuby platform. Things like database.yml, Gemfile will generated specifically for JRuby platform.
rails new myapp
# SQLite version 3.x
#   gem 'activerecord-jdbcsqlite3-adapter'

  adapter: sqlite3
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
  adapter: sqlite3
  database: db/test.sqlite3

  adapter: sqlite3
  database: db/production.sqlite3
source ''

gem 'rails', '3.0.10.rc1'

gem 'jruby-openssl'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://'

gem 'activerecord-jdbcsqlite3-adapter'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end
You can see in Gemfile the changes. It requires gem 'jruby-openssl' gem and gem 'activerecord-jdbcsqlite3-adapter' gem. Which is required for JRuby platform. Same work to generate for mysql and postgres.
rails new myapp -d mysql
And that’s all.!! Your Application is ready to run. Just do bundle install and all set. wOOtt..!! Post comments and discuss things if you guys still facing any issue. You can also post issue on Rails Issues and ask me to look into that. Some Useful links related to post:
  1. Activerecord-jdbc-adapter