Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails Step by Step

kares edited this page · 1 revision

This example shows how to create and deploy a simple Rails app using the embedded Java database H2 to a WAR using Warbler and JRuby-Rack.

Install Rails and the ActiveRecord adapters + driver for the H2 database:

jruby -S gem install rails activerecord-jdbch2-adapter

Install Warbler:

jruby -S gem install warbler

Make the "Blog" application

jruby -S rails new blog
cd blog

Copy this configuration into config/database.yml:

  adapter: jdbch2
  database: db/development_h2_database

  adapter: jdbch2
  database: db/test_h2_database

  adapter: jdbch2
  database: db/production_h2_database

Add the following to your application's Gemfile:

gem 'activerecord-jdbch2-adapter', :platform => :jruby

Generate a scaffold for a simple model of blog comments.

jruby script/rails generate scaffold comment name:string body:text

Run the database migration that was just created as part of the scaffold.

jruby -S rake db:migrate

Start your application on 3000 using WEBrick and make sure it works:

jruby script/rails server

Generate a production version of the H2 database for the application:

RAILS_ENV=production jruby -S rake db:migrate

Generate a custom Warbler WAR configuration for the blog application

jruby -S warble config

Edit config/warble.rb and add the following line after these comments:

# Additional files/directories to include, above those in config.dirs
# config.includes = FileList["db"]
config.includes = FileList["db/production_h2*"]

This will tell Warbler to include the just initialized production H2 database in the WAR.

Now generate the WAR file:

jruby -S warble war

This task generates the file: blog.war at the top level of the application as well as an exploded version of the war located at tmp/war.

The war should be ready to deploy to your Java application server.

Something went wrong with that request. Please try again.