 |
Rails 2.1 on GlassFish - it works!
Posted by arungupta on June 19, 2008 at 06:44 AM | Comments (0)
Rails 2.1 was released
earlier this month. GlassFish
provides a complete 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 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 JRuby
1.1.2 installation:
~/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:
~/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:
~/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:
~/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:
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

- Generate a Scaffold as described in TOTD
#28
~/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 >../../../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 >../../../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:
|
config.time_zone = 'Pacific Time (US & Canada)' |
- Creating a new scaffold entry shows the following screen:

Notice how default timezone is selected using Rails
2.1 Time Zone Support. After creating couple of entries (as
described in TOTD
#28), the page at "http://localhost:8080/runner/distances"
looks
like:

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 GlassFish
v3 Gem.
Let's see how:
- Install GlassFish v3 Gem as:
~/testbed/rails21/jruby-1.1.2
>bin/jruby -S gem
install glassfish
JRuby
limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating
metadata for 13 gems from http://gems.rubyforge.org/
.............
complete
Successfully
installed glassfish-0.2.0-universal-java
1 gem
installed |
- Deploy the previously created Rails application as:
~/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 |
The page at "http://localhost:3000/runner" looks like:

Let us know on GlassFish
Webtier Forum or Webtier
Alias if you tried any of your Rails application on
GlassFish. Please file bugs at GlassFish
Issue Tracker ("V3" as "Found in Version:" and "jruby" as
"Subcomponent:") if your app is not working.
Technorati: glassfish
v3 rubyonrails
jruby ruby gem
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
|