Thursday Nov 08, 2007

JRuby 1.0.2 released - Improved Windows experience and Rails 1.2.5 support

JRuby 1.0.2 was released last week.

A total of 99 issues were fixed but I'm particularly excited about JRUBY-1347, JRUBY-1350, JRUBY-1401 and JRUBY-1410. These are some issues that I faced (1347 here, 1350 here, 1401 here, 1410 here) on my primary development machine - Windows.

Here is the status report:

  • On Windows only, the latest Rails gem (1.2.5) is now working with stable release of JRuby (1.0.2 as of today).

  • On Windows only, GlassFish v3 gem does not work with JRuby 1.0.2 but works with the JRuby trunk (JRUBY-1549). The gem works correctly on Solaris and Mac.

  • JRuby 1.0.2 bundles will be available on GlassFish Update Center soon.

Now the details.

Here is the command sequence for creating and hosting a trivial Hello World on WEBrick:

  1. Install Rails

    C:\\testbed\\ruby\\jruby-1.0.2>bin\\jruby -S gem install rails --include-dependencies --no-ri --no-rdoc
    Bulk updating Gem source index for: http://gems.rubyforge.org
    Successfully installed rails-1.2.5
    Successfully installed activesupport-1.4.4
    Successfully installed activerecord-1.15.5
    Successfully installed actionpack-1.13.5
    Successfully installed actionmailer-1.3.5
    Successfully installed actionwebservice-1.2.5

  2. Create a template application

    C:\\workarea\\samples\\rails>\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby -S rails hello
     create
    create app/controllers
    create app/helpers
    create app/models
    create app/views/layouts
    create config/environments
    create components
    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/mocks/development
    create test/mocks/test
    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 public/.htaccess
    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/breakpointer
    create script/console
    create script/destroy
    create script/generate
    create script/performance/benchmarker
    create script/performance/profiler
    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/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. Add a controller

    C:\\workarea\\samples\\rails>cd hello

    C:\\workarea\\samples\\rails\\hello>\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby script\\generate controller say hello
    exists app/controllers/
    exists app/helpers/
    create app/views/say
    exists test/functional/
    create app/controllers/say_controller.rb
    create test/functional/say_controller_test.rb
    create app/helpers/say_helper.rb
    create app/views/say/hello.rhtml

  4. Edit Controller

    C:\\workarea\\samples\\rails\\hello>vim app\\controllers\\say_controller.rb

    Add  @hello_string = "Hello from 1.0.2" in hello helper. The updated file looks like:

    class SayController < ApplicationController

      def hello
        @hello_string = "Hello from 1.0.2"
      end
    end

  5. Edit View

    C:\\workarea\\samples\\rails\\hello>vim app\\views\\say\\hello.rhtml

    and add <%= @hello_string %> as the last line. The updated file looks like:

    <h1>Say#hello</h1>
    <p>Find me in app/views/say/hello.rhtml</p>
    <%= @hello_string %>

  6. Start WEBrick and view the page http://localhost:3000/say/hello in a browser window:

    C:\\workarea\\samples\\rails\\hello>\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby script\\server
    => Booting WEBrick...
    => Rails application started on http://0.0.0.0:3000
    => Ctrl-C to shutdown server; call with --help for options
    [2007-11-07 17:22:01] INFO WEBrick 1.3.1
    [2007-11-07 17:22:01] INFO ruby 1.8.5 (2007-11-01) [java]
    [2007-11-07 17:22:01] INFO WEBrick::HTTPServer#start: pid=11245030 port=3000
    127.0.0.1 - - [07/Nov/2007:17:22:38 PST] "GET /say/hello HTTP/1.1" 200 81
    - -> /say/hello

The GlassFish v3 Gem does not work with JRuby 1.0.2 (JRUBY-1549) on Windows. It works very well on Solaris and Mac. For Windows, you need to use the JRuby trunk (checkout and build):

After you've built the JRuby trunk, you can create a similar new application and run it on GlassFish v3 gem as:

  1. Download and Install the gem

    C:\\workspaces\\jruby-trunk>bin\\jruby -S gem install glassfish-gem-10.0-SNAPSHOT.gem
    Successfully installed GlassFish, version 10.0.0

  2. Start GlassFish v3 and view the page http://localhost:8080/hello/say/hello:

    C:\\workarea\\samples\\rails>\\workspaces\\jruby-trunk\\bin\\jruby -S glassfish_rails hello
    Nov 8, 2007 2:39:07 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter postConstruct
    INFO: Listening on port 8080
    Nov 8, 2007 2:39:08 PM com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
    INFO: Supported containers : php,phobos,jruby,web
    Nov 8, 2007 2:39:08 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
    INFO: New Servicing page from: C:\\workarea\\samples\\rails\\hello\\public
    Nov 8, 2007 2:39:15 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 7588 ms
    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO:

    Processing SayController#hello (for 127.0.0.1 at 2007-11-08 14:39:27) [GET]

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Session ID: 46e3279ab4f2d776b4d76010cc7b38af

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Parameters: {"action"=>"hello", "controller"=>"say"}

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Rendering say/hello

    Nov 8, 2007 2:39:27 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Completed in 0.01100 (90 reqs/sec) | Rendering: 0.00900 (81%) | 200 OK [http://localhost/hello/say/hello]

A comprehensive list of JRuby on GlassFish documentation is available here.

Technorati: jrubyonglassfish jruby glassfish windows rubyonrails v3 gem ruby

Thursday Sep 13, 2007

Announcing GlassFish Gem for Rails

Jerome has been working on GlassFish gem for Rails. Read the interesting discussion on dev@glassfish. This blog announces a technology preview of this gem and describes the steps to try it out.

  1. Download GlassFish Gem from here.

  2. If you already have JRuby on Rails configured, then skip this step. Otherwise you need to install JRuby on Rails.
    1. Download and Unzip JRuby 1.0.1 from here (lets say JRUBY_HOME).
    2. In JRUBY_HOME\\bin directory, install Rails plugin using the following command:

      jruby -S gem install rails -y --no-rdoc --no-ri

      The output of the command looks like:

      Bulk updating Gem source index for: http://gems.rubyforge.org
      Successfully installed rails-1.2.3
      Successfully installed activesupport-1.4.2
      Successfully installed activerecord-1.15.3
      Successfully installed actionpack-1.13.3
      Successfully installed actionmailer-1.3.3
      Successfully installed actionwebservice-1.2.3

  3. Some platform specific changes listed below are required due to bugs in JRuby 1.0.1.
    1. Only on Windows
      1. Edit "JRUBY_HOME\\bin\\_jrubyvars.bat" and replace

        for /r "%JRUBY_HOME%\\lib" %%i in (\*.jar) do @call "%~dp0_jrubysetcp" %%i

        with

        for %%i in ("%JRUBY_HOME%\\lib"\\\*.jar) do @call "%~dp0_jrubysetcp" %%i

        This change is required because "/r" switch causes the entire tree of the directory to be parsed instead of just including the JARs in JRUBY_HOME/lib directory. More details here. This is filed as bug #1347.
      2. The value of CLASSPATH environment variable increases exponentially with each execution of the gem. Then you start seeing the following error in your command shell:

        The input line is too long.
        :gotCP
        was unexpected at this time.


        This is a filed as bug #1350. A workaround is to start a new shell when you start seeing the error.
    2. Only on Macintosh: "JRUBY_HOME\\bin\\glassfish_rails" script executable permissions need to be set explicitly. This is filed as bug #1348.

  4. Install the GlassFish gem using the command:

    c:\\Downloads>\\jruby-1.0.1\\bin\\gem install glassfish-gem-10.0-SNAPSHOT.gem

    The output of the command looks like:

    Successfully installed GlassFish, version 10.0.0

    Notice, you need to invoke this command from the directory where the gem was downloaded.

  5. Create a new rails app using the following command:

    %JRUBY_HOME%\\bin\\jruby -S rails hello

    The output of the command looks like:

    create
    create app/controllers
    create app/helpers
    create app/models
    create app/views/layouts
    create config/environments
    create components
    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/mocks/development
    create test/mocks/test
    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 public/.htaccess
    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/breakpointer
    create script/console
    create script/destroy
    create script/generate
    create script/performance/benchmarker
    create script/performance/profiler
    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/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

  6. Start GlassFish for this newly created app using the following command:

    %JRUBY_HOME%\\bin\\jruby -S glassfish_rails hello

    You need to invoke the command from outside the application directory instead of the natural way (script\\server start). This will be fixed in the future builds. The output of the command looks like:

    Sep 13, 2007 1:32:42 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter postConstruct
    INFO: Listening on port 8080
    Sep 13, 2007 1:32:42 PM com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
    INFO: Supported containers : jruby,web,php,phobos
    Sep 13, 2007 1:32:43 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
    INFO: New Servicing page from: C:\\workarea\\samples\\rails\\hello\\public
    C:/jruby-1.0.1/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mail
    er.rb:49 warning: already initialized constant MAX_LINE_LEN
    Sep 13, 2007 1:32:51 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 8996 ms

  7. Now you can view the default GlassFish web page at "http://localhost:8080".

This verifies the basic installation of the GlassFish gem. Lets add a simple controller to our application.

  1. Add a controller to the application by changing to the directory "hello" and giving the command:

    jruby script\\generate controller say hello

    The output of the command looks like:

    exists app/controllers/
    exists app/helpers/
    create app/views/say
    exists test/functional/
    create app/controllers/say_controller.rb
    create test/functional/say_controller_test.rb
    create app/helpers/say_helper.rb
    create app/views/say/hello.rhtml

  2. In hello\\app\\views\\say directory, edit "hello.rhtml" such that it looks like:

    <h1>Say#hello</h1>
    <p>Find me in app/views/say/hello.rhtml</p>
    <%= @hello_string %>
  3. In hello\\app\\controllers directory, edit "say_controller.rb" such that it looks like:

    class SayController < ApplicationController
      def hello
        @hello_string = "Hello from Controller!"
      end
    end

  4. The page is now accessible at "http://localhost:8080/hello/say/hello".

This is hosted using GlassFish. Of course, the same application can be deployed on WEBrick by giving the command:

jruby script\\server webrick start

Try your applications on GlasFish gem and let us know by leaving a comment on this blog or sending an email to users@glassfish or posting to GlassFish forum.

You can also download GlassFish V3 standalone builds from here. The instructions to deploy a Rails application on GlassFish V3 are available here and on V2 here.

Technorati: jruby ruby rubyonrails glassfish jrubyonglassfish gem v3

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