This post originated from an RSS feed registered with Ruby Buzz
by James Britt.
Original Post: JRuby + Ramaze | Warbler -> Glassfish
Feed Title: James Britt: Ruby Development
Feed URL: http://feeds.feedburner.com/JamesBritt-Home
Feed Description: James Britt: Playing with better toys
I’m a big fan of Ramaze, mainly because it approaches that sweet spot of strong features with minimum magic. A recent Web app needed to use some Java libraries, and since Ramaze runs fine under JRuby I set out building the site.
I really wanted to deploy to Glassfish as well. Warbler is a terrific gem from Nick Sieger that will bundle up your Rack-based app, including any specified gems, and create a WAR file that can be deployed to a Java app server.
Last time (about a month or so ago) I tried this with a Ramaze app, I was not too successful. Since my application did not have much of a UI to it I opted to write a sparse Rack app instead.
However, my needs changed and I found myself starting to add assorted framework-y features, such as routing and templating, to the site. Rather than reinvent these particular wheels I thought to give Ramaze another shot. Having had to do some amount of trial-and-error experimentation to get even my simple Rack app running smoothly I figure perhaps my earlier frustration with Ramaze was because of my Warbler ignorance.
My renewed attempt didn’t start off so well, but I saw that my JRuby install of Ramaze was bit out of date, so I updated the gem. It looked as though something has been changed in the how Ramaze is dispatching requests because my ealrier errors vanished after the gem update.
A little tweaking of config.ru and config/warble.rb, and presto, it worked.
You can create a bare-bones Ramaze app by running the generator:
$ ramaze --create myapp
This gives you (among other things) start.ru and start.rb.
I renamed start.ru to config.ru and, in config.ru, replaced the require 'start' with most of the contents of start.rb. Here’s what it looks like:
Ramaze.trait[:essentials].delete Ramaze::Adapter
Ramaze.start!
run Ramaze::Adapter::Base
When you start out to warbleize your app, you run (assuming you have already create a config/ directory):
$ warble config
and you get config/warbler.rb. That file is, by default, full of stuff your Ramaze app doesn’t need. Here’s my warble.rb:
Warbler::Config.new do |config|
config.dirs = %w( controller model public view)
config.gems = %w( ramaze )
end
I then ran
$ jruby -S warble
and copied the resulting WAR file to the glassfish autodeploy dir.
And it Just Worked.
I expect no problems adding in my own libraries and the use of a database with an ORM. My first warbled Rack app was doing all that (Sequel with MySQL), and given that Ramaze is loaded and running and handling requests then adding that in should be a non-issue.
Now we can use Ruby’s most elegant Web framework with the fastest Ruby implementation and a robust, full-featured Web application management tool.