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

Comments:

[Trackback] Last week, Arun Gupta paid a visit to the NetBeans Ruby writers. It was great to finally meet this dynamo in person and find out what a nice guy he is. When we first started writing about NetBeans Ruby, we used Arun's blog Miles to Go as one of our r...

Posted by Insider Scoop From the Tutorial Divas on September 17, 2007 at 08:57 AM PDT #

2007-10-05 14:32:40 com.sun.enterprise.v3.services.impl.GrizzlyAdapter postConstruct
INFO: Listening on port 8080
2007-10-05 14:32:40 com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
INFO: Supported containers : php,phobos,jruby,web
2007-10-05 14:32:40 com.sun.grizzly.standalone.StaticResourcesAdapter <init>
INFO: New Servicing page from: /home/franz/ruby/projects/wybory/public
/home/franz/ruby/netbeans-ruby/ruby1/jruby-1.0.1/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer.rb:49 warning: already initialized constant MAX_LINE_LEN
2007-10-05 14:32:51 com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 12021 ms
2007-10-05 14:34:04
hi I try run glassfish_rails and i have errors

com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/prototype.js
2007-10-05 14:34:04 com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/effects.js
2007-10-05 14:34:04 com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /images/rails.png
[2]+ Unicestwiony jruby -S glassfish_rails wybory
franz@franz:~/ruby/projects>

Posted by Andrzej on October 04, 2007 at 10:45 PM PDT #

The same thing!
com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/prototype.js
2007-10-05 14:34:04 com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/effects.js
2007-10-05 14:34:04 com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /images/rails.png

Posted by Nick on October 05, 2007 at 04:31 AM PDT #

I tried again and don't see this error with a simple hello application. I'm using JRuby 1.0.1 and Rails 1.2.3. Here is what I see ...

-- cut here --
INFO: New Servicing page from: C:\\workarea\\samples\\rails\\hello\\public
C:/testbed/jruby-1.0.1/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer.rb:49 warning: already initialized constant MAX_LINE_LEN
Oct 5, 2007 11:46:25 AM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 14196 ms
Oct 5, 2007 11:46:59 AM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:

Processing SayController#hello (for 127.0.0.1 at 2007-10-05 11:46:59) [GET]

Oct 5, 2007 11:46:59 AM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Session ID: a2307820e82133c86cb87bfa437c8c3f

Oct 5, 2007 11:46:59 AM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Parameters: {"action"=>"hello", "controller"=>"say"}

Oct 5, 2007 11:46:59 AM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Rendering say/hello

Oct 5, 2007 11:46:59 AM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Completed in 0.01500 (66 reqs/sec) | Rendering: 0.01500 (100%) | 200 OK [http://localhost/hello/say/hello]
-- cut here --

Are you adding any other dependencies in your application ?

Posted by Arun Gupta on October 05, 2007 at 04:50 AM PDT #

No, I have simple empty aplication ...
when i run i browser

for example

http://localhost:8080/hello/

where hello is application name... i get standard index.html from public directory. But ! I don't get css, js, and any images, and i have this errors on glassfish_rails. When i see clear page without rails logo.

Posted by Andrzej on October 05, 2007 at 06:11 AM PDT #

What is your environment ? I'm running on Windows Vista and JDK 1.5.0_011. I'm certainly interested in reproducing this error and then I can debug it.

Posted by Arun Gupta on October 05, 2007 at 06:32 AM PDT #

Again I can only repeat - I have exactly the same as Adrzey does
I've tried to google around about this error and found this link to source file

http://fisheye5.cenqua.com/browse/~raw,r=1.1.2.4/glassfish/appserv-core/src/java/com/sun/enterprise/v3/server/GrizzlyAdapter.java

found the place in the source about "No adapter registered for..."

// TODO : a better job at error reporting
Utils.getDefaultLogger().info("No adapter registered for : " + req.requestURI().toString());

and it seems that this GrizzliAdapter can't find resource files. But why?

Maybe I have to correctly setup this `docRoot' variable?

Charles Nutter wrote in his post
http://headius.blogspot.com/2007/09/end-is-near-for-mongrel.html
about settings
ActionController::AbstractRequest.relative_url_root = "/<app name>/"
ActionController::CgiRequest.relative_url_root = "/<app name>/"
in environment.rb
I tried it but with no success

I have tried on Linux an Windows XP machines. On XP one I had even worse result.

Posted by Nick on October 05, 2007 at 06:38 AM PDT #

JDK 1.6_01 sorry for I don't remember the exact minor numbers in jdk version. That was at my office and now I'm already at home.

Posted by Nick on October 05, 2007 at 06:43 AM PDT #

The behavior that "Andrzej" and "Nick" have mentioned can be observed if the URL is specified as :
http://localhost:8080/hello

As Nick mentioned the sample page would be displayed correctly but any gifs do not appear and one would see the following error on the console :
Oct 11, 2007 11:54:13 AM com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/prototype.js
Oct 11, 2007 11:54:13 AM com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /javascripts/effects.js
Oct 11, 2007 11:54:13 AM com.sun.enterprise.v3.services.impl.GrizzlyAdapter service
INFO: No adapter registered for : /images/rails.png

I have observed this on both Mac and Solaris x86 platforms. But things work correctly if the URL is specified as http://localhost:8080/hello/

So it looks like if one misses out the last slash, somehow there is an issue in getting to the resources.

Need to investigate further why this is happening.

Posted by Pramod Gopinath on October 11, 2007 at 04:58 AM PDT #

Arun, I just tested out the Glassfish gem on several Rails applications: Beast, Mephisto, etc and they all exhibited the same problem on OSX with Firefox. Glassfish appears to serve CSS files as Content-type: text/plain which leads to unstyled HTML pages in Firefox. When I use Mongrel with the exact same codebase, the CSS is served as text/css and Firefox renders the pages perfectly. Is this a known issue?

Posted by Mike Perham on October 14, 2007 at 08:33 AM PDT #

As I had reported earlier there is a difference in behavior between http://localhost:8080/hello (does not load images,javascript.. correctly) and http://localhost:8080/hello/ (works correctly)

In glassfish V2 the URl of http://localhost:8080/hello is redirected to http://localhost:8080/hello/

So this is obviously a bug in the grizzly code. Have filed an issue against the web container.
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3776

Posted by Pramod Gopinath on October 16, 2007 at 09:54 AM PDT #

Bug, bug ... bug!

Many simple problems is in Glassfish V3, but how to posssible is add "future" bug in V3, when in V2 is OK? Who write and develope V3 not using V2 source code as base ? Maybe not use http units test ;)

Ok, I waiting for new GEM with bugfixed version of Glassfish :)

Posted by Andrzej Śliwa on October 16, 2007 at 03:28 PM PDT #

[Trackback] 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...

Posted by Arun Gupta's Blog on November 08, 2007 at 11:17 PM PST #

[Trackback] In an Earlier Post, I described how Mephisto (a popular web publishing system based on Ruby on Rails) can be deployed on GlassFish V3. Both JRuby and GlassFish has matured since then and this post will provide the updated instructions...

Posted by Arun Gupta's Blog on November 14, 2007 at 10:19 PM PST #

[Trackback] Jerome posted the instructions to build GlassFish v3 Gem for JRuby - very simple and easy. Software pre-requisite Subversion client (for example Tigris) Maven 2.0.x JRuby 1.0.x (I used JRuby 1.0.2 and lets say installed in JRUBY_HOME).&nbsp; Make sure ...

Posted by Arun Gupta's Blog on November 18, 2007 at 10:55 PM PST #

very interesting :)

Posted by satılık on December 09, 2007 at 07:14 PM PST #

[Trackback] JRuby 1.0.3 was recently released and so was Rails 2.0. I decided to try JRuby 1.0.3 + Rails 2.0 and realized that a few additional steps (because of Rails 2.0) are required to get a trivial Hello World applcation...

Posted by Arun Gupta's Blog on December 21, 2007 at 03:20 AM PST #

[Trackback] In my role of Technology Evangelist, I get the opportunity to meet a lot of community (folks like you :) all around the world. In the year 2007, I represented GlassFish (and related technologies - Metro, jMaki and Jersey) at...

Posted by Arun Gupta's Blog on January 01, 2008 at 07:53 AM PST #

[Trackback] Pramod published an updated JRuby Gem for GlassFish v3. Download the gem here. Here are the updates from last time: The Gem is now smaller - 2.4 MB instead of 2.9 MB (approx 20% smaller). The Gem is now using...

Posted by Arun Gupta's Blog on January 04, 2008 at 10:27 PM PST #

[Trackback] GlassFish v3 Gem allows JRuby-on-Rails application to be launched in GlassFish v3 server. It provides a robust alternative to WEBrick and Mongrel for development and deployment of your JRuby-on-Rails applications. The Gem was originally announced here...

Posted by Arun Gupta's Blog on February 07, 2008 at 08:33 PM PST #

thank you

very gooooooooooood

very nic

Posted by برامج on June 16, 2008 at 04:52 AM PDT #

JDK 1.6_01 sorry for I don't remember the exact minor numbers in jdk version. That was at my office and now I'm already at home.

Posted by BATTERY on November 27, 2008 at 08:51 AM PST #

When I open your site in your browser, Safari 4 in Mac OS X, some elements of the page and off to the side and the text is broken: ( Please help me How can I remove the problem

Posted by Single on December 27, 2009 at 03:09 AM PST #

Pretty interesting topic there, I think you covered it quite well, was a very interesting blog post to read.

Posted by annet on October 30, 2010 at 09:14 AM PDT #

Post a Comment:
Comments are closed for this entry.
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