Miles to go …

May 15, 2007

Ruby-on-Rails Hello World on GlassFish

Filed under: web2.0 — arungupta @ 3:03 pm

UPDATE: Simplified steps for GlassFish V2 are available here and for V3 here.

Ashish described how to create RoRaWAR (Ruby on Rails as Web ARchive). I decided to try these instructions on GlassFish V2 b46. Here are the steps I followed:

  1. Create a simple "Hello World" RoR application using NetBeans 6.0 M9 following this screencast. NetBeans IDE creates a standard Rails application for you which can be easily created using "rails hello_demo" command as well.
  2. Install the "goldspike" (nee rails-integration) plug-in by giving the following command:

    script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

    On a Windows machine, this command can be invoked as:

    ruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

    The correct installation of this plug-in can be confirmed by checking for the presence of "vendor/plugins/goldspike" directory in your application directory. This plug-in’s purpose is to WAR’up a RoR application.

  3. After the plug-in is installed, right-select the NetBeans project, select "Run Rake Target", select "Refresh Target List". This will add a new category, "war", of rake targets. Select "war", "standalone", "create" to create a stand-alone WAR file. This is equivalent to invoking the command "rake war:standalone:create". This will archive the Rails framework libraries in the WAR file.
  4. Drop this WAR file in "domains/domain1/autodeploy" directory of your GlassFish instance and you are done!

This is really simple. I’ll add database interaction in this app and report back.

Read more on Rails Integration with JavaEE servers.

Technorati: glassfish rubyonrails ror netbeans jruby ruby

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #6: Difference between Ruby Gem and Rails Plugin
  2. JRuby on Rails, NetBeans 6 and GlassFish V2 – Simplified Steps
  3. Ruby/JRuby Process Models Explained
  4. Rails and Java EE integration – Servlet co-bundled and invoked from Rails
  5. TOTD #32: Rails Deployment on GlassFish v3 from NetBeans IDE

13 Comments »

  1. [Trackback] Follow up from here. In this post I show how a Rails app can talk to database and then deployed as WAR on GlassFish V2. Here are the steps I followed: Deploy a RoR application as WAR on GlassFish using…

    Comment by Arun Gupta's Blog — May 16, 2007 @ 3:22 pm

  2. Nice posting! I was trying to add the goldspike plugin on Mac, and found that I had to call jruby explicitly to get it to work. My command looks like:
    platinum:~/devel/netbeans_projects/Patterns > jruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/pl
    ugins/goldspike

    Comment by John Stanford — June 10, 2007 @ 9:41 am

  3. John, thanks for the tip. This is how the command is invoked on Windows machine as well and mentioned in the blog entry.

    Comment by Arun — June 10, 2007 @ 5:04 pm

  4. gr8 post… thanks…
    I tried to follow the steps but
    ruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike
    seems to be not working… it does not error out …. just nothing happens… any reason behind ?

    Comment by Amit — June 13, 2007 @ 5:01 am

  5. Amit, after executing the command, do you see “vendor/plugins/goldspike” in your application directory ?

    Comment by Arun — June 13, 2007 @ 8:53 am

  6. [Trackback] Get ready for an interactive afternoon of coding and discussion on JRuby and GlassFish on Aug 8th in San Francisco, CA. In this free event, JRuby on Rails: Power plus simplicity, learn how to code and deploy a JRuby…

    Comment by Arun Gupta's Blog — August 7, 2007 @ 9:59 am

  7. [Trackback] Earlier in a three-part series (part1, part2, part3) I showed how a JRuby application can be deployed on GlassFish. This screencast consolidates all the entries together and shows how such an application can be developed and deployed using NetBeans…

    Comment by Arun Gupta's Blog — August 8, 2007 @ 9:46 am

  8. Hello. Thank you for your work. I am trying to follow the posted instructions for installing the Goldspike and unfortunately it does not work. I have NetBeans 6 M10 installed on Windows XP and when I execute the following command:
    C:\Program Files\NetBeans 6.0M10\ruby1\jruby-1.0\bin>jruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldsp
    ike
    I get the following error:
    Error opening script file: script\plugin (The system cannot find the path specif
    ied)

    SVN client is installed.

    Would you know what a solution to this issue might be? Thank you!

    Eugene

    Comment by Eugene — August 23, 2007 @ 6:49 am

  9. Just found a solution to my problem. Simple really.

    This was done with
    Product Version: NetBeans IDE 6.0 M10 (build 200706281431)
    Java: 1.6.0_01; Java HotSpot(TM) Client VM 1.6.0_01-b06
    System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
    Userdir: C:\Documents and Settings\xyz\.netbeans\6.0m10

    Create a Rails application in NetBeans
    Right click on the created Rails app and select "Rails plugins"
    Click on "Repositories" tab
    Click on "Add URL"
    In the pop-up window enter "http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/plugins" and click OK
    Wait for the repository to load
    Select the newly loaded repository
    Click on the "New Plugins" tab
    Wait for the list of plugins to load
    Select "goldspike: http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/plugins/goldspike/" plugin and click install
    Click OK in the pop-up window
    Wait for installation to finish
    Close two pop-up windows
    now use Arun Gupta’s instructions (http://blogs.sun.com/arungupta/entry/ruby_on_rails_hello_world)
    # The correct installation of this plug-in can be confirmed by checking for the presence of "vendor/plugins/goldspike" directory in your application directory. This plug-in’s purpose is to WAR’up a RoR application.
    # After the plug-in is installed, right-select the NetBeans project, select "Run Rake Target", select "Refresh Target List". This will add a new category, "war", of rake targets.

    Note: if you get an error regarding being unable to delete "rake-t", then using windows explorer navigate to "path to your RoR project\nbproject\private" and renate rake-t file to rake-t.old. Try "Refreshing Target List" again.

    Select "war", "standalone", "create" to create a stand-alone WAR file. This is equivalent to invoking the command "rake war:standalone:create". This will archive the Rails framework libraries in the WAR file.

    Note: war file will be created in "path to your RoR project" directory

    # Drop this WAR file in "domains/domain1/autodeploy" directory of your GlassFish instance and you are done!

    Note: app can be accessed via:

    http://myglassfishserver.myserver.com:8080/NameOfMyRailsApplication/controller/method

    Comment by Eugene — August 23, 2007 @ 7:32 am

  10. Eugene, This is exactly what is shown at:

    http://blogs.sun.com/arungupta/entry/screencast_web6_first_jruby_app

    Comment by Arun Gupta — August 23, 2007 @ 8:11 am

  11. Drop this WAR file in "domains/domain1/autodeploy" directory of your GlassFish instance and you are done!

    Comment by laptop batteries — November 26, 2008 @ 9:53 pm

  12. Hi,

    Thanks for your work. I followed your screencast but when I deploy the application to glassfish and browse to the the app, i get my rails app directory listing? Can someone help?

    Comment by LL — November 28, 2008 @ 10:03 pm

  13. Have you tried the recent screencast at: http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug ?

    -Arun

    Comment by Arun Gupta — December 1, 2008 @ 9:02 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress