TOTD #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem
By arungupta on Apr 27, 2009
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.
- Install Sinatra gem as:
~/tools/jruby >./bin/jruby -S gem install sinatra
JRuby limited openssl loaded. gem install jruby-openssl for full support.
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:
get '/hi' do
- 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:
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:
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