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
jruby -S gem install warbler
Make the "Blog" application
jruby -S rails new blog cd blog
Copy this configuration into config/database.yml:
development: adapter: jdbch2 database: db/development_h2_database test: adapter: jdbch2 database: db/test_h2_database production: 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.