Posted by
arungupta on June 19, 2008 at 6:44 AM PDT
Rails 2.1 was
href="http://weblog.rubyonrails.org/2008/6/1/rails-2-1-time-zones-dirty-caching-gem-dependencies-caching-etc">released
earlier this month. GlassFish
provides a complete
href="http://developers.sun.com/appserver/reference/techart/rails_gf/">development/deployment
environment for Rails applications. Some of the main reasons
for using GlassFish (instead of WEBrick or Mongrel)
are:
- Identical Development and Deployment environment
- Multiple Applications can be deployed on one Container
- Multiple requests can be handled by a single application
(with no extra configuration)
- Out-of-the-box Clustering, Load Balancing and High
Availability
- Database connection pooling
- Co-hosting Rails and Java EE applications
More details are available in
href="http://developers.sun.com/appserver/reference/techart/rails_gf/">Rails
powered by the GlassFish Application Server. This blog
provides detailed instructions to get started with Rails 2.1
on GlassFish.
- Install Rails 2.1 in a
href="http://dist.codehaus.org/jruby/jruby-bin-1.1.2.zip">JRuby
1.1.2 installation:
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
~/testbed/rails21/jruby-1.1.2
>bin/jruby -S gem
install rails --no-ri --no-rdoc
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating metadata for 253 gems from http://gems.rubyforge.org/
...............................................................................
...............................................................................
...............................................................................
................
complete
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed activesupport-2.1.0
Successfully installed activerecord-2.1.0
Successfully installed actionpack-2.1.0
Successfully installed actionmailer-2.1.0
Successfully installed activeresource-2.1.0
Successfully installed rails-2.1.0
6 gems installed |
- Create a new Rails app as:
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
~/testbed/rails21/jruby-1.1.2/samples/rails
>../../bin/jruby
-S rails -d mysql runner
create
create
app/controllers
create
app/helpers
create
app/models
create
app/views/layouts
create
config/environments
create
config/initializers
create db
create doc
create lib
create
lib/tasks
create log
create
public/images
create
public/javascripts
create
public/stylesheets
create
script/performance
create
script/process
create
test/fixtures
create
test/functional
create
test/integration
create
test/unit
create
vendor
create
vendor/plugins
create
tmp/sessions
create
tmp/sockets
create
tmp/cache
create
tmp/pids
create
Rakefile
create
README
create
app/controllers/application.rb
create
app/helpers/application_helper.rb
create
test/test_helper.rb
create
config/database.yml
create
config/routes.rb
create
config/initializers/inflections.rb
create
config/initializers/mime_types.rb
create
config/initializers/new_rails_defaults.rb
create
config/boot.rb
create
config/environment.rb
create
config/environments/production.rb
create
config/environments/development.rb
create
config/environments/test.rb
create
script/about
create
script/console
create
script/dbconsole
create
script/destroy
create
script/generate
create
script/performance/benchmarker
create
script/performance/profiler
create
script/performance/request
create
script/process/reaper
create
script/process/spawner
create
script/process/inspector
create
script/runner
create
script/server
create
script/plugin
create
public/dispatch.rb
create
public/dispatch.cgi
create
public/dispatch.fcgi
create
public/404.html
create
public/422.html
create
public/500.html
create
public/index.html
create
public/favicon.ico
create
public/robots.txt
create
public/images/rails.png
create
public/javascripts/prototype.js
create
public/javascripts/effects.js
create
public/javascripts/dragdrop.js
create
public/javascripts/controls.js
create
public/javascripts/application.js
create
doc/README_FOR_APP
create
log/server.log
create
log/production.log
create
log/development.log
create
log/test.log |
- Start GlassFish as:
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
~/testbed/glassfish/v3/tp2/glassfishv3-tp2/glassfish
>java
-DJRUBY_HOME=/Users/arungupta/testbed/rails21/jruby-1.1.2 -jar
modules/glassfish-10.0-tp-2-SNAPSHOT.jar
Jun 17, 2008 6:14:21 PM com.sun.enterprise.glassfish.bootstrap.ASMain
main
INFO: Launching GlassFish on HK2 platform
Jun 17, 2008 6:14:22 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 8080
Jun 17, 2008 6:14:22 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 8181
Jun 17, 2008 6:14:22 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 4848
Jun 17, 2008 6:14:22 PM
com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
Jun 17, 2008 6:14:22 PM com.sun.enterprise.v3.server.AppServerStartup
run
INFO: Glassfish v3 started in 974 ms |
- Deploy the newly created application as:
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
~/testbed/rails21/jruby-1.1.2/samples/rails
>~/testbed/glassfish/v3/tp2/glassfishv3-tp2/glassfish/bin/asadmin
deploy runner
Command deploy executed successfully. |
and the GlassFish console shows:
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
Jun
17, 2008 6:14:41 PM com.sun.enterprise.rails.RailsDeployer
registerAdapter
INFO: Loading application runner at /runner
Jun 17, 2008 6:14:41 PM
INFO: Starting Rails instances
Jun 17, 2008 6:14:49 PM
SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for
full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Jun 17, 2008 6:14:51 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
INFO: Rails instance instantiation took : 9066ms
Jun 17, 2008 6:14:51 PM com.sun.enterprise.v3.deployment.DeployCommand
execute
INFO: Deployment of runner done is 9168 ms |
The default page at "http://localhost:8080/runner" shows
src="http://blogs.sun.com/arungupta/resource/ror/rails21-v3-tp2-default-page.png">
- Generate a Scaffold as described in
href="http://blogs.sun.com/arungupta/entry/totd_28_getting_started_with">TOTD
#28
style="text-align: left; width: 100%; font-family: monospace;"
cellpadding="2" cellspacing="2">
~/testbed/rails21/jruby-1.1.2/samples/rails/runner
>../../../bin/jruby
-S rake db:create
(in /Users/arungupta/testbed/rails21/jruby-1.1.2/samples/rails/runner)
~/testbed/rails21/jruby-1.1.2/samples/rails/runner >
style="font-weight: bold;">../../../bin/jruby
script/generate scaffold distance miles:float run_at:datetime
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
exists
app/models/
exists
app/controllers/
exists
app/helpers/
create
app/views/distances
exists
app/views/layouts/
exists
test/functional/
exists
test/unit/
exists
public/stylesheets/
create
app/views/distances/index.html.erb
create
app/views/distances/show.html.erb
create
app/views/distances/new.html.erb
create
app/views/distances/edit.html.erb
create
app/views/layouts/distances.html.erb
create
public/stylesheets/scaffold.css
create
app/controllers/distances_controller.rb
create
test/functional/distances_controller_test.rb
create
app/helpers/distances_helper.rb
route map.resources :distances
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/distance.rb
create test/unit/distance_test.rb
create test/fixtures/distances.yml
create db/migrate
create
db/migrate/20080618012326_create_distances.rb
~/testbed/rails21/jruby-1.1.2/samples/rails/runner >
style="font-weight: bold;">../../../bin/jruby -S rake
db:migrate
(in /Users/arungupta/testbed/rails21/jruby-1.1.2/samples/rails/runner)
== 20080618012326 CreateDistances: migrating
==================================
-- create_table(:distances)
-> 0.0080s
== 20080618012326 CreateDistances: migrated (0.0090s)
=========================
|
- Edit line 44 of "config/environment.rb" to change the
default timezone from "UTC" to "Pacific Time (US & Canada)".
The updated line looks like:
cellpadding="2" cellspacing="2">
config.time_zone = 'Pacific Time (US & Canada)' |
- Creating a new scaffold entry shows the following screen:
src="http://blogs.sun.com/arungupta/resource/ror/rails21-v3-tp2-new-runner.png">
Notice how default timezone is selected using
href="http://blogs.sun.com/arungupta/resource/ror/rails21-v3-tp2-new-runner.png">Rails
2.1 Time Zone Support. After creating couple of entries (as
described in
href="http://blogs.sun.com/arungupta/entry/totd_28_getting_started_with">TOTD
#28), the page at "http://localhost:8080/runner/distances"
looks
like:
src="http://blogs.sun.com/arungupta/resource/ror/rails21-v3-tp2-runner-entries.png">
Notice how "-0700" is shown which is the offset for US Pacific Time
during daylight savings.
The same application can also be easily deployed on
href="http://rubyforge.org/projects/glassfishgem/">GlassFish
v3 Gem.
Let's see how:
- Install GlassFish v3 Gem as:
cellpadding="2" cellspacing="2">
style="font-family: monospace;">~/testbed/rails21/jruby-1.1.2
>bin/jruby -S gem
install glassfish
style="font-family: monospace;">
JRuby
limited openssl loaded. gem install jruby-openssl for full support.
style="font-family: monospace;">
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
style="font-family: monospace;">
Updating
metadata for 13 gems from http://gems.rubyforge.org/
style="font-family: monospace;">
.............
style="font-family: monospace;">
complete
style="font-family: monospace;">
Successfully
installed glassfish-0.2.0-universal-java
style="font-family: monospace;">
1 gem
installed |
- Deploy the previously created Rails application as:
cellpadding="2" cellspacing="2">
style="font-family: monospace;">~/testbed/rails21/jruby-1.1.2/samples/rails
>../../bin/jruby
-S glassfish_rails runner
Jun 17, 2008 6:39:37 PM com.sun.enterprise.glassfish.bootstrap.ASMain
main
INFO: Launching GlassFish on HK2 platform
Jun 17, 2008 6:39:37 PM
com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available
Jun 17, 2008 6:39:38 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3000
Jun 17, 2008 6:39:38 PM
com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator
configureSSL
WARNING: pewebcontainer.all_ssl_protocols_disabled
Jun 17, 2008 6:39:38 PM
com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator
configureSSL
WARNING: pewebcontainer.all_ssl_ciphers_disabled
Jun 17, 2008 6:39:38 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3131
Jun 17, 2008 6:39:38 PM
com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3838
Jun 17, 2008 6:39:39 PM
com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
Jun 17, 2008 6:39:39 PM com.sun.enterprise.rails.RailsDeployer
registerAdapter
INFO: Loading application runner at /
Jun 17, 2008 6:39:39 PM
INFO: Starting Rails instances
Jun 17, 2008 6:39:44 PM
SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for
full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Jun 17, 2008 6:39:45 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
INFO: Rails instance instantiation took : 6710ms
Jun 17, 2008 6:39:45 PM com.sun.enterprise.v3.server.AppServerStartup
run
INFO: Glassfish v3 started in 8053 ms
style="font-family: monospace;"> |
The page at "http://localhost:3000/runner" looks like:
src="http://blogs.sun.com/arungupta/resource/ror/rails21-v3-tp2-gem-page.png">
Let us know on
href="http://forums.java.net/jive/forum.jspa?forumID=138">GlassFish
Webtier Forum or Webtier
Alias if you tried any of your Rails application on
GlassFish. Please file bugs at
href="https://glassfish.dev.java.net/issues/enter_bug.cgi?issue_type=DEFECT">GlassFish
Issue Tracker ("V3" as "Found in Version:" and "jruby" as
"Subcomponent:") if your app is not working.
Technorati: glassfish
v3
href="http://technorati.com/tag/rubyonrails">rubyonrails
jruby
href="http://technorati.com/tag/ruby">ruby
href="http://technorati.com/tag/gem">gem