Wednesday Jun 18, 2008

Rails 2.1 on GlassFish - it works!


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.
  1. 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
  2. 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
  3. 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
  4. 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


  5. 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) =========================
  6. 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)'
  7. 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:
  1. 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
  2. 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

Sunday Jun 01, 2008

Tic Tac Toe using Rails and Grails on GlassFish v3


GlassFish v3 is a modular (OSGi compliant), embeddable (runs in-VM) and extensible (hosts non-Java applications) Application Server. The "extensible" part was demonstrated during JavaOne 2008 by deploying Rails, Grails and Django sample application on GlassFish v3 Technology Preview 2. This blog announces the availability of Rails, Grails and (of course!) Java EE version of the demo code.

The sample application is a simple multi-player game that can be played on Internet and deployed on GlassFish. One of the simplest multi-player game is Tic-Tac-Toe. The complete instructions to checkout, build, deploy and run the sample are available here. The demo can certainly be improved by using the best practices from Rails and Grails and I'll work on them in next few days.

The demo is played in 2 different browser windows (tested on Firefox, Safari & IE). The clicks in the grid on one browser are displayed on the other browser (propagated using GlassFish Comet) and row and column winners are shown.



Some points highlighted by the demo are:
  • GlassFish v3 supports deployment of Rails and Grails applications, in addition to traditional Java EE apps.
  • GlassFish v3 has a completely modular architecture as evident by the pluggability of JRuby/Rails.
  • Features of the underlying GlassFish runtime can be accessed.
    • Any click in the grid is pushed to the endpoint and then propagated to all the clients using GlassFish Comet. So effectively, now you can build Comet-enabled applications using Rails and Grails.
    • Rails application is deployed as a composite application where Serlvet is bundled with the application and accessed from the View.
Check out the demo now!

You can learn about the support of different Dynamic Languages on GlassFish on glassfish-scripting.dev.java.net. Send us feedback on webtier@glassfish.dev.java.net or GlassFish WebTier Forum.

Technorati: conf javaone javaone08 jruby ruby rubyonrails grails javee glassfish v3 netbeans

Thursday May 29, 2008

GlassFish and jMaki @ RailsConf Today


I was originally planning to give my first talk at Rails Conf on "Rails powered by GlassFish and jMaki". But I cannot travel for personal reasons and instead Craig McClanahan, who is an excellent speaker, has graciously agreed to speak. Craig has been involved with Rails, GlassFish and jMaki for a long time so feel free to poke hime at the talk, in the exhibit hall and afterwards.

Thanks Craig for the wishes! I had a great time @ RailsConf 2007 (here and here) but life is about priorities :)

More information about support for Dynamic Languages and their Frameworks on GlassFish can be found on glassfish-scripting.dev.java.net.

Technorati: conf railsconf railsconf08 jruby ruby rubyonrails glassfish jmaki webtier

Wednesday May 28, 2008

JRuby 1.1.2 released - Getting Started with v3 Gem


JRuby 1.1.2 was released yesterday - download here!

The highlights are:
  • Startup time drastically reduced
  • YAML symbol parsing >100x faster
  • Performance, threading, and stack depth improvements for method calls
  • Fixed several nested backref problems
  • Fixed bad data race (JRUBY-2483)
  • Gazillions of bigdecimal issues fixed
  • 95 issues resolved since JRuby 1.1.1
Getting started is really simple, just follow the steps listed below.

Unzip JRuby 1.1.2 zip bundle ...

~/testbed/ >unzip ~/Downloads/jruby-bin-1.1.2.zip
Archive:  /Users/arungupta/Downloads/jruby-bin-1.1.2.zip
   creating: jruby-1.1.2/
   creating: jruby-1.1.2/bin/
  inflating: jruby-1.1.2/bin/_jrubycleanup.bat 
  inflating: jruby-1.1.2/bin/_jrubyvars.bat 
  . . .
  inflating: jruby-1.1.2/share/ri/1.8/system/Zlib/crc_table-c.yaml 
  inflating: jruby-1.1.2/share/ri/1.8/system/Zlib/zlib_version-c.yaml 
  inflating: jruby-1.1.2/share/ri/1.8/system/created.rid 
  inflating: jruby-1.1.2/share/ri/1.8/system/fatal/cdesc-fatal.yaml 
~/testbed >

... and then install Rails and GlassFish v3 gem ...

~/testbed/jruby-1.1.2 >bin/jruby -S gem install rails glassfish --no-ri --no-rdoc
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Bulk updating Gem source index for: http://gems.rubyforge.org/
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
Successfully installed rails-2.0.2
Successfully installed glassfish-0.2.0-universal-java
6 gems installed

... and verify ...

~/testbed/jruby-1.1.2 >bin/jruby -S gem list g

\*\*\* LOCAL GEMS \*\*\*

glassfish (0.2.0)

... and now host any of your Rails application on v3 Gem (such as Redmine) ...

~/testbed/redmine >../jruby-1.1.2/bin/jruby -S glassfish_rails redmine-0.7
May 28, 2008 12:07:19 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on HK2 platform
May 28, 2008 12:07:19 PM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3000
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_protocols_disabled
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_ciphers_disabled
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3131
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3838
May 28, 2008 12:07:21 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
May 28, 2008 12:07:21 PM com.sun.enterprise.rails.RailsDeployer registerAdapter
INFO: Loading application redmine-0.7 at /
May 28, 2008 12:07:21 PM 
INFO: Starting Rails instances
May 28, 2008 12:07:26 PM 
SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
May 28, 2008 12:07:32 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
INFO: Rails instance instantiation took : 11481ms
May 28, 2008 12:07:32 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 12787 ms

Below is the screenshot from a previously deployed Redmine application, now on the GlassFish gem:



Simple isn't it ?

If your Rails application does not work on the gem, file bugs here with "jruby" as "subcomponent" (default version is "v3").

Alternatively, you can download GlassFish v3 TP2 and deploy your applications to leverage complete Java EE functionality.

You can also configure JRuby 1.1.2 as a Ruby platform in NetBeans 6.1 as described in TOTD #27.

Technorati: jruby ruby rubyonrails glassfish v3 gem redmine netbeans webtier

Thursday May 22, 2008

Redmine on GlassFish - Ruby-on-Rails Project Management Application



Redmine
is a flexible project management web application written using Ruby on Rails framework. The feature list is pretty comprehensive from the usual suspects like multiple projects, role-based control, forums/wikis/SCM for each project to enterprise level features such as LDAP-authentication and multiple languages. It is cross-platform and cross-database and deploys very nicely on GlassFish v3.

GlassFish v3 modularity and extensibility allows Rails applications to be deployed without any modification (no WARing). This blog explains the steps on how to deploy Redmine on GlassFish and shows some screenshots later. More documentation is available in Redmine Guide.
  1. Check out the most stable release of Redmine by giving the command:

    ~/testbed/redmine >svn co http://redmine.rubyforge.org/svn/branches/0.7-stable redmine-0.7
  2. Configure the database
    1. Start your MySQL server 

      ~/testbed/redmine >sudo mysqld_safe --user root
      Starting mysqld daemon with databases from /usr/local/mysql/data
    2. Create the database as:

      ~/testbed/redmine/redmine-0.7 >../jruby-1.1.1/bin/jruby -S rake db:create
      (in /Users/arungupta/testbed/redmine/redmine-0.7)
    3. Migrate the database as:

      ~/testbed/redmine/redmine-0.7 >../jruby-1.1.1/bin/jruby -S rake db:migrate
      (in /Users/arungupta/testbed/redmine/redmine-0.7)
      == 1 Setup: migrating =========================================================
      -- create_table("attachments", {:force=>true})
         -> 0.2840s
      -- create_table("auth_sources", {:force=>true})
         -> 0.0540s
      -- create_table("custom_fields", {:force=>true})
         -> 0.0430s
      -- create_table("custom_fields_projects", {:id=>false, :force=>true})
         -> 0.0080s
      -- create_table("custom_fields_trackers", {:id=>false, :force=>true})
         -> 0.0500s

      . . .

      == 90 ChangeVersionsNameLimit: migrating ======================================
      -- change_column(:versions, :name, :string, {:limit=>nil})
         -> 0.0220s
      == 90 ChangeVersionsNameLimit: migrated (0.0220s) =============================

      == 91 ChangeChangesetsRevisionToString: migrating =============================
      -- change_column(:changesets, :revision, :string, {:null=>false})
         -> 0.0210s
      == 91 ChangeChangesetsRevisionToString: migrated (0.0230s) ====================

      == 92 ChangeChangesFromRevisionToString: migrating ============================
      -- change_column(:changes, :from_revision, :string)
         -> 0.0130s
      == 92 ChangeChangesFromRevisionToString: migrated (0.0150s) ===================
  3. Download, Install and Configure GlassFish v3
    1. Download GlassFish v3 from here.
    2. Unzip the downloaded bundle.
    3. Add the following fragment as the last line in "glassfishv3-tp2/glassfish/config/asenv.conf" file:

      JRUBY_HOME="/Users/arungupta/testbed/redmine/jruby-1.1.1"
  4. Deploy Redmine as:

    ~/testbed/redmine >./glassfishv3-tp2/glassfish/bin/asadmin deploy redmine-0.7
    Command deploy executed successfully.

    ... and the GlassFish console shows:

    May 21, 2008 4:58:30 PM com.sun.enterprise.rails.RailsDeployer registerAdapter
    INFO: Loading application redmine-0.7 at /redmine-0.7
    May 21, 2008 4:58:30 PM 
    INFO: Starting Rails instances
    May 21, 2008 4:58:37 PM 
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    May 21, 2008 4:58:42 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: Rails instance instantiation took : 11979ms
    May 21, 2008 4:58:42 PM com.sun.enterprise.v3.deployment.DeployCommand execute
    INFO: Deployment of redmine-0.7 done is 12091 ms
That's it, your application is ready to be used! Here are some screen snapshots from my trial run:


















Rails powered by the GlassFish Application Server provides all the good reasons on why you should consider using GlassFish instead of the traditional deployment models for Ruby-on-Rails applications.

This application is also covered in LAB 5539 as part of FREE 20-week Ruby-on-Rails course by Sang "with Passion" Shin.

Technorati: web2.0 rubyonrails jruby ruby glassfish redmine

Monday May 19, 2008

FREE 20-week Ruby-on-Rails Programming Course - with Passion!


Sang Shin and Brian Leonard are starting a new free online course of "Ruby, JRuby and Rails Application Development (with Passion!)". The course is taken online and will start from Jul 15, 2008.

The objective of this course are "This course will go through briefly the basics of Ruby (and JRuby) programming language first.  The rest of the course will be devoted to learning Rails functionality such as Active Record, Active Controller, and Active View.  Attendees will acquire sufficient knowledge in order to write reasonably sophisticated Rails application upon completion." Read more details here.

In this course, you'll learn various NetBeans and GlassFish tricks for Ruby-on-Rails development and deployment.

Read the Registration FAQ and send a blank email to ruby-on-rails-programming-with-passion-subscribe@googlegroups.com to register.

This course runs very much like a regular college course in which the students are expected to do weekly homework after studying the learning material and doing the hands-on
lab. By registering with the email address above, students can ask/answer questions. Some quick links ...
It is FREE and can be taken online, so what are you waiting for - register now!

Technorati: rubyonrails jruby ruby glassfish netbeans web2.0

Sunday May 18, 2008

Benefit of using JRuby-on-Rails: Using Java 2D power within Rails


One of the main advantages of using JRuby-on-Rails instead of Ruby-on-Rails is to harness the power of Java libraries available in the Java platform. The Java 2D API is a set of classes for advanced 2D graphics and imaging, and provides extensive support for image compositing and alpha channel images, a set of classes to provide accurate color space definition and conversion, and a rich set of display-oriented imaging operators.

Jennifer published a new blog showing image-filtering effect (negative, grayscale, brigthen, sharpen). Read the complete entry.

A more comprehensive tutorial for JRuby-on-Rails on GlassFish v3 TP2 (also Jennifer's work) is available here.

Technorati: rubyonrails ruby jruby glassfish v3 java2d web2.0

Saturday May 17, 2008

Ask The "JRuby + NetBeans + GlassFish" Experts


NetBeans and GlassFish have changed the landscape of Ruby, JRuby and Rails development and deployment. Code completion, debugging, similar development and deployment environment and many other features (NetBeans, GlassFish) together make it a compelling offering.

Tor Norbye, Brian Leonard and Charles Nutter are fielding questions on Ruby/JRuby/Rails support in the NetBeans IDE and GlassFish in a week-long Ask The Expert session (May 19-23). A complete archive of the Q&A will be available later. You can submit your question here.

If "Ask The Expert" window is missed, the questions can always be asked on user@jruby.codehaus.org, users@glassfish.dev.java.net and users@ruby.netbeans.org.

Technorati: ruby jruby rubyonrails netbeans glassfish web2.0

Wednesday May 14, 2008

WAR-based Packaging and Deployment of Rails on GlassFish - Goldspike, RailServlet, Warbler, Rack, ...


WAR-based packaging and dispatching of Rails application on Java Application Servers is going through third iteration based what is used for packaging and dispatching:
  • Goldspike + RailsServlet: The first iteration was WAR-packaging of Rails app as defined by Goldspike plugin (nee Rails-integration) and using RailsServlet (part of Goldspike) for dispatching.
  • Warbler + RailsServlet: The second iteration (slightly short lived) overcame the shortcomings of Goldspike (packaging with sane defaults, fast, light-weight, and flexible configuration) by using Warbler for packaging. It decoupled packaging and dispatching by doing only packaging and allowing for pluggable dispatching mechanism. RailsServlet continues to be the default Servlet binding mechanism. This is the version currently supported by GlassFish v2 Update Center.
  • Warbler + Rack:  Nick released JRuby-Rack (JRuby version of Rack, also see Introducing Rack and Docs) last week. And so the third iteration is using Warbler packaging and Rack-based dispatching. JRuby-Rack provides a more seamless connection between the Servlet environment and Rack.

The JRuby-Rack wiki says "JRuby-Rack is a lightweight adapter for the Java servlet environment that allows any Rack-based application to run unmodified in a Java servlet container. JRuby-Rack supports Rails, Merb, as well as any Rack-compatible Ruby web framework.".

This means that, other than Rails, conceptually Merb applications (which also use Rack for deployment) can now also be deployed on GlassFish. This blog entry explains how to deploy a simple Rack-based Rails application.
  1. Install Rails and JRuby-Rack (as part of Warbler) as:

    ~/testbed/jruby-1.1.1 >bin/jruby -S gem install rails warbler --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 289 gems from http://gems.rubyforge.org/
    ..............................................................................................................................
    ..............................................................................................................................
    .....................................
    complete
    Successfully installed activesupport-2.0.2
    Successfully installed activerecord-2.0.2
    Successfully installed actionpack-2.0.2
    Successfully installed actionmailer-2.0.2
    Successfully installed activeresource-2.0.2
    Successfully installed rails-2.0.2
    Successfully installed warbler-0.9.9
    7 gems installed
  2. Create a template Rails app as:

    ~/testbed/jruby-1.1.1/samples/rails >../../bin/jruby -S rails hello -d mysql
          create 
          create  app/controllers
          create  app/helpers
          create  app/models
          create  app/views/layouts
          create  config/environments
          . . .
          create  doc/README_FOR_APP
          create  log/server.log
          create  log/production.log
          create  log/development.log
          create  log/test.log
  3. Disable database access from the application by uncommenting line 21 (remove "#" at the beginning) from "config/environment.rb" as:

       config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
  4. Create a WAR file as:

    ~/testbed/jruby-1.1.1/samples/rails/hello >../../../bin/jruby -S warble
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    jar cf hello.war -C tmp/war .

  5. A new file "hello.war" is generated in the current directory.
  6. The generated WAR file can be easily deployed on GlassFish.
    1. Download and Install GlassFish v2 UR2 from here.
    2. Start GlassFish Application Server as:

      ~/testbed/glassfish/v2ur2/glassfish >bin/asadmin start-domain --verbose
      Starting Domain domain1, please wait.
      May 13, 2008 11:23:44 AM com.sun.enterprise.admin.servermgmt.launch.ASLauncher buildCommand
      INFO:
      /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java
      . . .

      [#|2008-05-13T11:34:13.252-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=10;_ThreadName=main;4848;|WEB0712: Starting Sun-Java-System/Application-Server HTTP/1.1 on 4848|#]

      [#|2008-05-13T11:34:13.691-0700|INFO|sun-appserver9.1|javax.enterprise.system.core.selfmanagement|_ThreadID=10;_ThreadName=main;|SMGT0007: Self Management Rules service is enabled|#]

      [#|2008-05-13T11:34:13.718-0700|INFO|sun-appserver9.1|javax.enterprise.system.core|_ThreadID=10;_ThreadName=main;|Application server startup complete.|#]
    3. Deploy the WAR on GlassFish as:

      ~/testbed/jruby-1.1.1/samples/rails/hello >~/testbed/glassfish/v2ur2/glassfish/bin/asadmin deploy hello.war
      Command deploy executed successfully.

      The output in the GlassFish console looks like:

      [#|2008-05-13T11:34:23.330-0700|INFO|sun-appserver9.1|javax.enterprise.system.tools.admin|_ThreadID=14;_ThreadName=httpWorkerThread-4848-0;/private/tmp/s1astempdomain1server1547440193/hello.war;|ADM1006:Uploading the file to:[/private/tmp/s1astempdomain1server1547440193/hello.war]|#]

      [#|2008-05-13T11:34:26.019-0700|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=15;_ThreadName=Thread-30;|deployed with moduleid = hello|#]

      [#|2008-05-13T11:34:30.626-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412: WebModule[/hello] ServletContext.log():Info: using runtime pool timeout of 30 seconds|#]

      [#|2008-05-13T11:34:30.626-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412: WebModule[/hello] ServletContext.log():Warning: no initial runtimes specified.|#]

      [#|2008-05-13T11:34:30.627-0700|INFO|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-4848-1;|PWC1412: WebModule[/hello] ServletContext.log():Warning: no max runtimes specified.|#]
    4. The default Rails page is now visible at "http://localhost:8080/hello" as shown below:

  7. Add some functionality to the application to show Servlet and Rack integration
    1. Add a Controller and View as

      ~/testbed/jruby-1.1.1/samples/rails/hello >../../../bin/jruby script/generate controller home index
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
            exists  app/controllers/
            exists  app/helpers/
            create  app/views/home
            exists  test/functional/
            create  app/controllers/home_controller.rb
            create  test/functional/home_controller_test.rb
            create  app/helpers/home_helper.rb
            create  app/views/home/index.html.erb
    2. Change the "index" helper method in "app/controllers/home_controller.rb" as:

      def index
              @greeting = "Hello from Rack!!"

              # access Servlet Context
              @server_info = $servlet_context.get_server_info
              # alternative way to get Servlet Context
              #@server_info2 = request.env['java.servlet_context'].get_server_info

              # access Servlet Request
              @method = request.env['java.servlet_request'].get_method
              @request_uri = request.env['java.servlet_request'].get_request_uri
              @protocol = request.env['java.servlet_request'].get_protocol
              @port = request.env['java.servlet_request'].get_server_port
      end
    3. Add the following fragment as the last line in "app/views/home/index.html.erb":

      <%= @greeting %><br><br>
      Hosted on "<%= @server_info %>" on port "<%= @port %>"<br>
      <%= @method %> <%= @request_uri %> <%= @protocol %>
  8. Re-create and deploy the WAR file
    1. Re-create the WAR file as explained in step 4.
    2. Re-deploy the WAR file as explained in step 5.3.
    3. Now "http://localhost:8080/hello/home/index" shows the output as:

The magic fragment in "tmp/war/WEB-INF/web.xml" is:

  <filter>
    <filter-name>RackFilter</filter-name>
    <filter-class>org.jruby.rack.RackFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>RackFilter</filter-name>
    <url-pattern>/\*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
  </listener>

And also "WEB-INF/lib/jruby-rack-0.9.jar" is bundled in the WAR.
Let us know if you try Rack-based deployment of Merb applications on GlassFish.

Technorati: rubyonrails jruby ruby rack merb glassfish web2.0

Sunday May 04, 2008

GlassFish v3 Gem 0.2.0 released


A newer version of GlassFish v3 Gem for Ruby on Rails is now available.

What's new ?
  • Codebase aligned with GlassFish v3 Technology Preview 2
  • Previous version (0.1.2) had some packaging issues which increased the size but now it's back to sweet 2.8 Mb.
Check if previously installed by using the following command:

~/testbed/jruby-1.1.1 >bin/jruby -S gem list glassfish

\*\*\* LOCAL GEMS \*\*\*

glassfish (0.1.2)

If already installed (as indicated by the list of gems) then uinstall it using the following command:

~/testbed/jruby-1.1.1 >bin/jruby -S gem uninstall glassfish
Successfully uninstalled glassfish-0.1.2-universal-java
Remove executables:
        glassfish_rails, asadmin, asadmin.bat

in addition to the gem? [Yn]  y
Removing glassfish_rails
Removing asadmin
Removing asadmin.bat

And then install it again as:

~/testbed/jruby-1.1.1 >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
Successfully installed glassfish-0.2.0-universal-java
1 gem installed

Updating the gem is giving unpredictable results (mostly not updating) and will be investigated later.

Rails powered by the GlassFish Application Server explains why GlassFish is a better deployment option for Rails applications.

All the latest information about the gem can be found at GlassFish JRuby wiki or JRuby wiki.

Please use the gem and send us feedback on GlassFish forums, dev@glassfish or gem mailing list.

Technorati: rubyonrails jruby ruby glassfish v3 gem
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today