TOTD #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem
src="http://blogs.sun.com/arungupta/resource/ror/ruby-frameworks-glassfish.png">
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 href="http://www.sinatrarb.com/intro.html">Getting Started
for complete details. Even though Sinatra is not a MVC framework but href="http://github.com/quirkey/sinatra-gen/tree/master">sinatra-gen
may be used to generate new Sinatra projects.
GlassFish
Gem can easily run Rails,
Merb, href="http://www.sinatrarb.com/">Sinatra, and any
other Ruby framework applications based upon href="http://rack.rubyforge.org/">Rack. href="http://blogs.sun.com/arungupta/entry/totd_70_jruby_and_glassfish">TOTD
#70 shows how to run Rails applications and href="http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merb">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.
- Install Sinatra gem as:
style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
~/tools/jruby > style="font-weight: bold;">./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...
- Create a directory "sinatra-sample", create a file
"hello.rb" in that directory with the contents shown below:
style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end
- Run your sample using GlassFish gem as:
style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
~/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:
alt=""
src="http://blogs.sun.com/arungupta/resource/ror/sinatra-hello-world-output.png">
Neat and simple!
You'll hear all about it at
href="http://blog.arungupta.me/2009/04/27/glassfish-and-netbeans-at-rails-conf-2009.aspx">Develop
with Pleasure, Deploy with Fun: GlassFish and NetBeans for a Better
Rails Experience at
href="http://en.oreilly.com/rails2009/">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
href="http://blogs.sun.com/arungupta/tags/totd">here.
Technorati: totd
glassfish
jruby
sinatra
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 1529 reads





