- Feb
- 19
- 2008
How to Create and Deploy a JRuby app to the GlassFish gem in 10 minutes or less on Mac OS X
By: Robert Dempsey | Tags:The JRuby and Glassfish teams have made installing, building, and launching a JRuby on Rails app a rather trivial process. Glassfish, a Java app server, has been reduced in size from a 22.5 MB install to 2.5 MB Ruby gem (not too shabby for a full app server). If you need the full monty (not covered here) or you need to deploy to another Java app server, install the warbler gem. The combination of Rails 2.0.2 (stable), JRuby 1.1 RC2, the Glassfish gem, and JDK 1.6 is not only breaking down enterprise barriers but speeding up apps all over the place.
So how do we get started with all this, in 10 minutes or less? Let’s take a look.
Overview
Here are the steps we will take to build our first JRuby on Rails application:
- Download and install JRuby
- Install Rails and the dependent gems
- Install the Open-SSL gem
- Install the GlassFish gem
- Create a test JRuby on Rails app
- Deploy our little app to the GlassFish gem
“Make it so Number 1″
First, download JRuby 1.1 RC2. Unpack it into a directory and edit your bash_profile to include the bin directory in your $PATH so you can easily call JRuby executables. Mine looks like this: /Users/rdempsey/Documents/jruby/jruby-1.1RC2/bin. Open up a terminal session and type jruby –version to see if you are successful. If you are, you should see something like this:
$ jruby --version ruby 1.8.6 (2008-02-16 rev 5944) [i386-jruby1.1RC2]
Now that JRuby is installed (and yes, ready to go), let’s install Rails:
$ jruby -S gem install rails --no-ri --no-rdoc Successfully installed activesupport-2.0.2 Successfully installed activerecord-2.0.2 Successfully installed actionpack-2.0.2 Successfully installed actionmailer-2.0.2 Successfully installed activeresource-2.0.2 Successfully installed rails-2.0.2 6 gems installed
For full SSL support (and why not have it) install the jruby-openssl gem too.
$ jruby -S gem install jruby-openssl --no-ri --no-rdoc Successfully installed jruby-openssl-0.1.1 1 gem installed
Now for the Glassfish gem. One command should get us going.
$ jruby -S gem install glassfish Successfully installed glassfish-0.1.1-universal-java 1 gem installed
Great. How are we on time? 8 minutes to go? Perfect. Let’s create our test Rails app.
$ jruby -S rails --database mysql testapp ... Rails code being generated ...
Change into the directory of testapp and fire up your favorite editor. I like TextMate, though the new NetBeans is looking HOT. Once inside, open up config/database.yml and change the username/password for your MySQL server as necessary. In your terminal and in the root of your app, run the following rake command to create the development database:
$ rake db:create
It may not seem like anything happened, but if you fire up your MySQL gui tool of choice (or go command line) you will see that the testapp_development database has been created. Now to create a migration and test things out. Let’s make a widget.
$ script/generate scaffold Widget name:string description:text
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/widgets
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/widgets/index.html.erb
create app/views/widgets/show.html.erb
create app/views/widgets/new.html.erb
create app/views/widgets/edit.html.erb
create app/views/layouts/widgets.html.erb
create public/stylesheets/scaffold.css
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/widget.rb
create test/unit/widget_test.rb
create test/fixtures/widgets.yml
create db/migrate
create db/migrate/001_create_widgets.rb
create app/controllers/widgets_controller.rb
create test/functional/widgets_controller_test.rb
create app/helpers/widgets_helper.rb
route map.resources :widgets
With Rails 2.0.2 we don’t have to specify the timestamp fields, those are automatically added to the migration. Now, run “rake db:migrate” to add your database table.
$ rake db:migrate (in /Users/rdempsey/Documents/jruby/testapp) == 1 CreateWidgets: migrating ================================================= -- create_table(:widgets) -> 0.4622s == 1 CreateWidgets: migrated (0.4624s) ========================================
And now for the fun part, deploying the app to the GlassFish gem. Change to the parent directory of your application (getting out of the root directory) and run the following command:
$ jruby -S glassfish_rails testapp Feb 18, 2008 5:03:00 PM com.sun.enterprise.v3.server.AppServerStartup run ... GlassFish firing up... INFO: Loading application testapp at / Starting Rails instances ... Rails instantiation info... INFO: Glassfish v3 started in 24766 ms
As with Mongrel, the GlassFish gem starts our server on port 3000. Fire up your browser and go to http://localhost:3000/widgets and play around.

Pretty nice eh? Looks like we have time to spare as well. Go make yourself that next pot of coffee and see what else you can do with this new found power. Let us know how things turn out as well.
Connect with me on LinkedIn, Twitter, or recommend me on Working With Rails.
Share this post
Other posts you may enjoy
You can leave a response, or trackback from your own site.


8 Responses to “How to Create and Deploy a JRuby app to the GlassFish gem in 10 minutes or less on Mac OS X”
On February 19th, 2008 at 9:50 am Damien said:
As mentioned in other places, JRuby, and by extension Glashfish, is slow to get load but once it starts it is fast - faster than Ruby 1.8.6 from our meagre non-scientific tests. Good stuff, we’ll be keeping a close eye on future JRuby developments.
On February 19th, 2008 at 11:40 am Matthew Williams said:
It’s definitely slick and easy to setup but it’s got some time before it’s ready for the masses. I’ve got a JRuby app that works perfectly with mongrel but when deploying with the Glassfish gem I get all sorts of quirky behaviors in regards to some AJAX activities. Bummer.
But, I’ve submitted a ticket for the problem and hopefully they’ll tackle it soon.
Great post to get people up and running though.
On February 19th, 2008 at 1:59 pm Robert Dempsey said:
Matt, that’s a good point. The GlassFish team has requested feedback on the gem as they are still working out kinks. Thanks for the feedback.
On February 19th, 2008 at 3:14 pm Arun Gupta said:
Thanks for the entry Robert! jruby-openssl is not required to run GlassFish gem though. Please send more feedback at:
GlassFish forum: http://forums.java.net/jive/forum.jspa?forumID=56
or
Dev alias: dev@glassfish.dev.java.net
or
Gem mailing list: http://rubyforge.org/mail/?group_id=5450
On February 21st, 2008 at 5:29 am James Branam said:
Hi,
My name is James Branam and I’m the NetBeans Community Docs Manager. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org/wiki/view/CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.
On February 21st, 2008 at 9:23 am Rails Podcast Brasil - Episódio 6 said:
[...] JRuby 1.1 RC2 [...]
On March 13th, 2008 at 9:05 pm Pramod Gopinath said:
Thanks for the great post. Wanted to inform you that today, I have released a new version of the GlassFish V3 gem. Further details can be found at my blog : http://blogs.sun.com/pramodg/entry/glassfish_v3_gem_v0_12
On April 1st, 2008 at 9:10 am Rails Podcast Brasil - Episódio 6 said:
[...] JRuby 1.1 RC2 [...]