Miles to go …

April 28, 2009

TOTD #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem

Filed under: glassfish, netbeans, sinatra, totd — arungupta @ 6:00 am


Sinatra is a DSL for quickly creating web-applications in Ruby with minimal effort. Like Rails and Merb, Sinatra is not an MVC framework and basically follows a flat-file structure instead. The framework define conventions such as location of static files and views, bootstrap, dev/production/test environment variables, filters, helpers, TDD, and much more.  Read Getting Started for complete details. Even though Sinatra is not a MVC framework but sinatra-gen may be used to generate new Sinatra projects.

GlassFish Gem can easily run Rails, Merb, Sinatra, and any other Ruby framework applications based upon Rack. TOTD #70 shows how to run Rails applications and TOTD #53 shows to run Merb applications. This TOTD will explain how to run a trivial Sinatra application. A later blog will describe how to plug a generic Rack-based framework.

Lets see how to get started with Sinatra using JRuby and GlassFish gem.

  1. Install Sinatra gem as:

    ~/tools/jruby >./bin/jruby -S gem install sinatra
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed sinatra-0.9.1.1
    1 gem installed
    Installing ri documentation for sinatra-0.9.1.1…
    Installing RDoc documentation for sinatra-0.9.1.1…

  2. Create a directory “sinatra-sample”, create a file “hello.rb” in that directory with the contents shown below:
    require ‘rubygems’
    require ’sinatra’
    get ‘/hi’ do
      “Hello World!”
    end

  3. Run your sample using GlassFish gem as:
    ~/tools/jruby/samples/sinatra-sample >../../bin/jruby -S glassfish
    Log file /Users/arungupta/tools/jruby-1.2.0/samples/sinatra-sample/log/development.log does not exist. Creating a new one…
    Starting GlassFish server at: 192.168.1.145:3000 in development environment…
    Writing log messages to: /Users/arungupta/tools/jruby-1.2.0/samples/sinatra-sample/log/development.log.
    Press Ctrl+C to stop.

    And then the output is available at “http://localhost:3000/hi” and looks like:

Neat and simple!

You’ll hear all about it at Develop with Pleasure, Deploy with Fun: GlassFish and NetBeans for a Better Rails Experience at Rails Conf next week.

Here is the order in which I’ll seek any help:

The next blog will show how to create a Sinatra CRUD application and run it using GlassFish.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all the tips is available here.
Technorati: totd glassfish jruby sinatra

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #80: Sinatra CRUD application using Haml templates with JRuby and GlassFish Gem
  2. TOTD #52: Getting Started with Merb using GlassFish Gem
  3. TOTD #63: jmx4r gem – How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
  4. TOTD #85: Getting Started with Django Applications on GlassFish v3
  5. TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress