Thursday Mar 13, 2008

GlassFish v3 gem 0.1.2 released

Pramod announced the release of GlassFish v3 Gem ver 0.1.2. The focus of this release is bugfixes:
After #4228 fix, you can easily follow TOTD#28 to create a scaffold using Rails 2.0 and deploy it on GlassFish gem instead of WEBrick - works on JRuby 1.1 RC2.

You can verify if have 0.1.1 version by giving the command:
Macintosh-187:jruby-1.1RC2 arungupta$ bin/jruby -S gem list -d glassfish

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

glassfish (0.1.1)
    GlassFish V3 Application Server for JRuby
You can update to the most recent version by giving the command:

Macintosh-187:jruby-1.1RC2 arungupta$ bin/jruby -S gem update glassfish
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating installed gems...
Updating metadata for 634 gems from http://gems.rubyforge.org
.............................................................................................................................
.............................................................................................................................
.............................................................................................................................
.............................................................................................................................
.............................................................................................................................
.........
complete
Attempting remote update of glassfish
Successfully installed glassfish-0.1.2-universal-java
1 gem installed
Gems updated: glassfish

And then again verify using the following command:
Macintosh-187:jruby-1.1RC2 arungupta$ bin/jruby -S gem list -d glassfish

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

glassfish (0.1.2, 0.1.1)
    GlassFish V3 Application Server for JRuby

If you installed version 0.1.0 then you need to uninstall it and install the new version using the following commands:
bin/jruby -S gem uninstall GlassFish
bin/jruby -S gem install glassfish

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.

File issues in JIRA or RubyForge or GlassFish Issue Tracker.

Technorati: glassfish v3 jruby ruby rubyonrails gem

Tuesday Mar 11, 2008

BitNami's JRubyStack = JRuby + Rails + GlassFish Gem + MySQL all bundled together

BitNami provides easy-to-use, integrated and multiplatform install bundles for different open source apps. They released JRubyStack last week which includes JRuby 1.1 RC2, Rails 2.0.2, GlassFish v3 Gem 0.1.1, MySQL 5.0.45 and some other miscellaneous components. The components mentioned here are all you need to get started with hosting your JRuby-on-Rails applications on GlassFish. Refer to release notes for more details.

The steps below walks you through installation of JRubyStack. It shows how this stack provides an integrated and ready-to-use bundle for hosting your applications on GlassFish:

  1. Install JRubyStack
    1. Download JRubyStack from here. Click on the installer to see:


       
    2. Clicking on "Next >" brings the following screen:



      Even though it shows "JRuby on Rails" component but it includes everything, including GlassFish v3 Gem & MySQL server, in it.
    3. Further in the installation process, change the database user name from default "jrubystack" to "root". Take all other defaults through out the installation process.
    4. After the installation is completed, the following program menu is added


       
  2. After the bundle is installed, it's ready to use - MySQL server is started, a default application is created in "C:\\Users\\Arun Gupta\\BitNami JRubyStack projects\\jrubystack" and hosted using GlassFish v3 gem at "http://localhost:3000". Here is the output shown in the console window started by JRubyStack:

    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Init service : com.sun.enterprise.v3.services.impl.CmdLineParamProcessor@1d9e5ad
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Init service : com.sun.enterprise.v3.server.SystemTasks@33c3e6
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Init service : com.sun.enterprise.v3.services.impl.LogManagerService@1b70f9e
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Init service : com.sun.enterprise.v3.services.impl.HouseKeeper@666d83
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
    INFO: Supported containers : web,jruby,phobos
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Startup service : Deployment
    Mar 10, 2008 2:49:26 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Startup service : org.glassfish.deployment.autodeploy.AutoDeployService@15925c0
    Mar 10, 2008 2:49:27 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter <init>
    INFO: Listening on port 3000
    Mar 10, 2008 2:49:27 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter <init>
    INFO: Listening on port 3131
    Mar 10, 2008 2:49:27 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter <init>
    INFO: Listening on port 3838
    Mar 10, 2008 2:49:27 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Startup service : com.sun.enterprise.v3.services.impl.GrizzlyService@eccfe7
    Mar 10, 2008 2:49:28 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
    INFO: New Servicing page from: C:\\Users\\Arun Gupta\\BitNami JRubyStack projects\\jrubystack\\public
    Mar 10, 2008 2:49:28 PM com.sun.enterprise.rails.RailsDeployer load
    INFO: Loading application . at /
    Starting Rails instances
    Mar 10, 2008 2:49:58 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: Rails instance instantiation took : 30451ms
    Mar 10, 2008 2:49:58 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Startup service : Application Loader
    Mar 10, 2008 2:49:58 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 32229 ms

Now you have a template app that can be used to experiment with different features of GlassFish Gem. A similar bundle can be easily hand-crafted using the steps described here.

More details about GlassFish and JRuby can be found @ GlassFish wiki and JRuby wiki. Help us test your application on the v3 gem and file issues in JIRA or GlassFish Issue Tracker.

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

Technorati: bitnami jrubystack jruby ruby rubyonrails glassfish v3 gem

Tuesday Feb 19, 2008

TOTD #28: Getting Started with Rails 2.0 Scaffold

Rails 2.0 changes the way Scaffold works. This blog walks you through the steps to create a simple CRUD application using Scaffold in Rails 2.0.
  1. Download & Install JRuby 1.1 RC2.
  2. Install Rails using the following command:

    jruby -S gem install rails
  3. Create a new Rails app using the following command:

    cd samples; mkdir rails; cd rails
    jruby -S rails books -d mysql
  4. Start MySQL server in a different shell using the following command:

    sudo /usr/local/mysql/bin/mysqld_safe --console
  5. Creat the database using the following command:

    cd books
    jruby -S rake db:create

    This creates the database defined by RAILS_ENV (Development is default). Here are some other new database-related commands:

    db:create:all Create all the databases (_Development, _Test, _Production)
    db:drop Drops your database
    db:reset Drop and Re-create your database, including migrations
  6. Generate a scaffold using the following command:

    jruby script/generate scaffold book title:string author:string isbn:string description:text


    The output of the command looks like:

          exists  app/models/
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/books
          exists  app/views/layouts/
          exists  test/functional/
          exists  test/unit/
          create  app/views/books/index.html.erb
          create  app/views/books/show.html.erb
          create  app/views/books/new.html.erb
          create  app/views/books/edit.html.erb
          create  app/views/layouts/books.html.erb
          create  public/stylesheets/scaffold.css
      dependency  model
          exists    app/models/
          exists    test/unit/
          exists    test/fixtures/
          create    app/models/book.rb
          create    test/unit/book_test.rb
          create    test/fixtures/books.yml
          create    db/migrate
          create    db/migrate/001_create_books.rb
          create  app/controllers/books_controller.rb
          create  test/functional/books_controller_test.rb
          create  app/helpers/books_helper.rb
          route  map.resources :books


    There is no need to create the model explicitly as was the case in previous version of Rails. This creates the "db/migrate/001_create_books.rb" migration which looks like:

    class CreateBooks < ActiveRecord::Migration
      def self.up
        create_table :books do |t|
          t.string :title
          t.string :author
          t.string :isbn
          t.text :description

          t.timestamps
        end
      end

      def self.down
        drop_table :books
      end
    end
  7. Create the database tables using the following command:

    jruby -S rake db:migrate
  8. Deploy the application on WEBrick using the following command:

    jruby script/server


    The application is now available at "http://localhost:3000/books" and looks like:

    Rails2 CRUD Blank Page
  9. Click on "New book" to see a page as shown below (with values entered):

    Rails2 CRUD New Entry
    Click on Create button. After 2 entries have been entered, it looks like as shown below:

    Rails 2 CRUD Multiple Entries
That's it, you've created  a simple Rails 2.0 CRUD application.

You can also deploy this application easily on GlassFish v3 gem. Just follow the instructions here and enjoy!

I'll post a follow up blog where this is much more simplifed using NetBeans 6.1 builds where JRuby 1.1 and Rails 2.0.2 are already integrated.

Technorati: totd ruby jruby rubyonrails rails2 scaffold crud netbeans glassfish v3 gem

Saturday Feb 16, 2008

GlassFish v3 gem on JRuby 1.1 RC2

JRuby 1.1 RC2 was released earlier today an GlassFish v3 gem works like a charm on it :)

Read the complete announcement here. The key features of RC2 are:
  1. 260 issues resolved
  2. Large IO refactoring
  3. Less memory than previous release
    1. Control total number of JIT'd methods
    2. Support a JIT cache between runtimes to return permgen
    3. 50-70% reduction in generated methods
Here are the steps for quick verification on v3 gem ...
  1. Download JRuby 1.1 RC2
  2. Install Rails and create a simple Rails application as described in TOTD #24.
  3. Install GlassFish v3 gem using the command as shown below:

    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.1.1-universal-java
    1 gem installed
  4. And now the simple application can be easily deployed on GlassFish gem as:

    jruby -S glassfish_rails hello

    Notice this command needs to be given from the parent directory of the application. The Applcation environment is as shown below:

    JRuby 1.1 RC2 Application Environment

    and the application output looks like exactly as expected:

    JRuby 1.1 RC2 Application Output
More details about GlassFish and JRuby can be found @ GlassFish wiki and JRuby wiki. Help us test your application on the v3 gem and file issues in JIRA or GlassFish Issue Tracker.

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

Technorati: jruby ruby rubyonrails glassfish v3 gem

Wednesday Feb 13, 2008

GlassFish v3 Gem - 0.1.1 available

Pramod released an updated version 0.1.1 of the JRuby GlassFish v3 gem.

What's New ? - Mainly alignment with Rails convention
  1. The name of the gem is changed from "GlassFish" to "glassfish".
  2. The default port number is 3000.
  3. Applications are deployed at root context ("/"). So the default application is now deployed "http://localhost:3000/home/index" instead of "http://localhost:8080/temp/home/index".
And then there are some other improvements:
  1. The number of concurrent requests can now be set using a command-line argument (instead of "-J-Djruby.runtime"). So 2 Rails instances can be created using the following command:

    jruby -S glassfish_rails temp -n 2
  2. Rails instances are created in parallel to improve the startup time of the gem.
How to install it ?

If you installed 0.1.0 version of the gem, then you need to uninstall using the following command:

bin/jruby -S gem uninstall GlassFish
Successfully uninstalled GlassFish-0.1.0-java
Remove executables and scripts for
'glassfish_rails, asadmin, asadmin.bat' in addition to the gem? [Yn]  Y
Removing glassfish_rails
Removing asadmin
Removing asadmin.bat


And then install the new gem using the following command:

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.1.1-universal-java
1 gem installed


And for a fresh check out of JRuby trunk, here is the list of gems shown:

bin/jruby -S gem list

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

actionmailer (2.0.2)
actionpack (2.0.2)
activerecord (2.0.2)
activeresource (2.0.2)
activesupport (2.0.2)
glassfish (0.1.1)
rails (2.0.2)
rake (0.8.1)
sources (0.0.1)


Read more details about the this newly released gem here.

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.

File issues in JIRA or GlassFish Issue Tracker.

Technorati: ruby jruby glassfish v3 gem rubyforge rubyonrails

Thursday Feb 07, 2008

GlassFish v3 Ruby Gem - New Home on RubyForge

Ruby Forge Icon 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.

UPDATE (Feb 14): A 0.1.1 version of the gem is released which will change the installation process.

The Gem was originally announced here and then updated here. All along, the Gem was living a nomadic life on download.java.net. Now it has found a permanent home on http://rubyforge.org/projects/glassfishgem/. We are excited to release version 0.1.0 of Gem co-located with other standard gems such as RubyGems, Rails and RMagick. This new and permanent home provides a much more seamless installation of v3 gem. Here are the highlights:
  • The Gem replaces WEBrick as the development container and a pack of Mongrels front-ended by light-weight Web server + Capistrano for management by one command and one process (think "eco-friendly").
  • Works with both JRuby 1.0.3 and JRuby 1.1RC1.
  • Multiple applications can be deployed in one instance of gem, each in their own context root and running on separate ports (details below).
  • Each application can serve multiple requests concurrently. This can be configured by the number of JRuby runtimes using -J-Djruby.runtime as a command-line property (details below).
  • The applications deployed on this Gem can easily make use of pooled resources such as database connections as explained in TOTD #9.
  • The released version is 0.1.0. Even though a preview version of Gem was released earlier, the version number is starting from scratch because of the newly found permanent home. 
  • Installing the Gem is a seamless and integrated process as explained below.
How to install the Gem ?

After you've downloaded and unzipped JRuby 1.0.3, go to JRUBY_HOME directory and install the gem by giving the following command:

bin/jruby -S gem install GlassFish
Need to update 24 gems from http://gems.rubyforge.org
........................
complete
Select which gem to install for your platform (java)
 1. GlassFish 0.1.0 (java)
 2. Skip this gem
 3. Cancel installation
> 1
Successfully installed GlassFish-0.1.0-java


Once the gem is installed, "glassfish_rails" script is available in JRUBY_HOME/bin directory. The exact same commands work for installing the gem in JRuby 1.1RC1 as well.

How to deploy an application on Gem ?

TOTD #24 shows how to develop a JRuby-on-Rails applications with JRuby 1.0.3 and JRuby 1.1 RC1 and tested using WEBrick. To deploy these applications on the newly installed gem, use the following command:

cd .. (go to parent directory of the application)
jruby -S glassfish_rails hello


Now the app is deployed at "http://localhost:8080/hello/say/hello".

How to configure the number of concurrent requests ?

The default number of concurrent requests that can be handled by an application deployed Gem is 1. If your application hosted on the Gem needs to handle concurrent requests then you need to specify the command-line option "-J-Djruby.runtime=NNN", where NNN is the number of expected concurrent requests. For example, if your application needs to handle 4 concurrent requests then the command to host your application will look like:

jruby -J-Djruby.runtime=4 -S glassfish_rails hello

How to host multiple applications ?

Multiple applications can be hosted on GlassFish gem by modifying the default port number on which the Gem is started. The ports that need to be changed are: "http-listener-1", "http-listener-2" and "admin-listener".

For now, the port numbers need to be modified by manually editing "jruby-1.0.3/lib/ruby/gems/1.8/gems/GlassFish-0.1.0-java/domains/domain1/config/domain.xml" file. Search for the string in first column, replace the port attribute of that XML element with the value in second column and the third column shows the default value:

Search String New Port Default
http-listener-1 8081 8080
http-listener-2 8182 8181
admin-listener 4849 4848

Any subsequent application deployed on GlassFish gem will now be hosted on http://localhost:8081/<context-root>/<controller>/<view> where <context-root> is the name of your Rails application.

A command-line switch, similar "-J-Djruby.rutime" will be provided in the near future.

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

File issues in JIRA or GlassFish Issue Tracker.

Technorati: ruby jruby glassfish v3 gem rubyforge

Friday Jan 04, 2008

GlassFish v3 Gem Updated

Pramod published an updated JRuby Gem for GlassFish v3. Download the gem here.

Here are the updates from last time:
  1. The Gem is now smaller - 2.4 MB instead of 2.9 MB (approx 20% smaller).
  2. The Gem is now using the latest v3 codebase, including Grizzly JRuby module 1.6.1.
  3. 2 Rails instances are created instead of the default one. So now 2 requests can be invoked in parallel and they both will be served instead of returning a blank page for the pending request. This explains/resolves the issue reported here.
  4. The list of known issues is now available

    1. #3856 - Default Rails page gives 404
    2. #3964 - Option to specify port at the command-line
    3. #3965 - Port conflict should be resolved transparently
    4. #3966 - Blank page returned if no Rails instance is available
    5. #3968 - Provide a means to configure number of Rails instances
    6. #3971 - Usage of v3 gem needs to be consistent with WEBrick

    Please file bugs if you see any other issues.
Ad of course, you can BYOG (Build Your Own Gem :)

Either way, once the Gem is installed then go ahead and use it as described below:
  1. Create a template app as:

    jruby -S rails hello
  2. Create a controller and view as:

    cd hello
    jruby script/generate controller say hello
  3. Edit controller as:

    vi app/controllers/say_controller.rb

    and add the following variable in hello helper method:

    @hello_string = "v3 Gem is getting polished!"
  4. Edit view as:

    vi app/views/say/hello.rhtml

    and add the following string at the bottom:

    <%= @hello_string %>
  5. Ad deploy the application on GlassFish v3 gem as:

    cd ..
    jruby -S glassfish_rails hello
That's it! The following output in the console confirms successful start of the Gem:

Jan 4, 2008 3:35:52 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
INFO: New Servicing page from: /Users/arungupta/testbed/r126/jruby-1.0.3/bin/hello/public
Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Startup service : Application Loader
Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Startup service : Grizzly on port 8080
Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 8567 ms


The application is deployed at http://localhost:8080/hello/say/hello and shows the output as:

GlassFish v3 gem - Simple App output

And http://localhost:8080/hello is displayed in the browser as shown below:

Default Rails page with v3 gem

And you can try more advanced applications like Mephisto as described here.

Technorati: ruby jruby glassfish v3 gem

Friday Dec 21, 2007

JRuby 1.0.3 + Rails 2.0 Hello World - Additional Steps Required


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 up and running. Here are the steps:

  1. Unzip JRuby 1.0.3.
    1. Make sure to set JAVA_HOME and JRUBY_HOME.
    2. Also include JAVA_HOME/bin and JRUBY_HOME/bin in PATH for convenience.
  2. Install Rails 2.0 as shown below:

    ~/samples/jruby arungupta$ jruby -S gem install rails --include-dependencies --no-ri --no-rdoc
    Bulk updating Gem source index for: http://gems.rubyforge.org
    Successfully installed rails-2.0.2
    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
  3. Create a simple app using the following steps
    1. Create a template app as:

      jruby -S rails --database mysql hello or jruby -S rails -d mysql hello

      It's important to specify --database mysql otherwise Rails 2.0 uses sqlite3 as the default database.
    2. Add a Controller and View as:

      cd hello
      jruby script/generate controller say hello
    3. Edit the controller as:

      vi app/controllers/say_controller.rb

      and add the following variable in "hello" helper method:

      @hello_string = ""
    4. Edit the View as:

      vi app/views/say/hello.html.erb

      and add the following as last line:

      <%= @hello_string %>


      Notice, the view extension is .html.erb instead of .rhtml.
  4. Download, Install and Configure MySQL (additional step for Rails 2.0)
    1. Mac OS comes pre-installed with MySQL in /usr/local/mysql directory. Start the server as:

      sudo ./bin/mysqld_safe

      Alternatively, you can download and install MySQL Universal server (only .dmg format, not tar.gz format as specified here).
    2. Create a database as:

      sudo ./bin/mysqladmin create hello_development
  5. Start the WEBrick server (in hello directory) as:

    jruby script/server
That's it, now your trivial Hello World application is deployed using JRuby 1.0.3 + Rails 2.0 and displays the output in a browser window as:

JRuby 1.0.3 + Rails 2.0 Hello World

Want to try this application on GlassFish v3 gem (download or build your own - now down to 2.4 MB) ?

Technorati: ruby jruby rails mysql glassfish v3 gem

Sunday Nov 18, 2007

TOTD #18: How to Build The GlassFish v3 Gem for JRuby ?

Jerome posted the instructions to build GlassFish v3 Gem for JRuby - very simple and easy. A binary version of Gem is available here.

  1. Software pre-requisite
    1. Subversion client (for example Tigris)
    2. Maven 2.0.x
    3. JRuby 1.0.x (I used JRuby 1.0.2 and lets say installed in JRUBY_HOME).  Make sure JRUBY_HOME/bin is in your path.
  2. Build the Gem
    1. As explained in Jerome's entry, you can check out complete GlassFish v3 workspace or just the Gem code. Here is how you'll check out only the Gem code on a Windows machine using Tigris Subversion client:



      And after the check out is complete, you'll see:

    2. Build the gem by giving the command:

      mvn install

      And success is achieved by seeing the following in the console:

      [INFO] (in C:/workspaces/glassfish/gem/target/dependency/glassfish)
      [WARNING] mkdir -p pkg
      [INFO] Successfully built RubyGem
      [INFO] Name: GlassFish
      [WARNING] mv GlassFish-10.0.0-java.gem pkg/GlassFish-10.0.0-java.gem
      [INFO] Version: 10.0.0
      [INFO] File: GlassFish-10.0.0-java.gem
      [INFO] [install:install]
      [INFO] Installing C:\\workspaces\\glassfish\\gem\\target\\gem-10.0-SNAPSHOT.jar to C:\\Users\\Arun Gupta\\.m2\\repository\\org\\glassfish\\distributions\\gem\\10.0-SNAPSHOT\\gem-10.0-SNAPSHOT.jar
      [INFO] [install:install-file {execution: install-gem}]
      [INFO] Installing C:\\workspaces\\glassfish\\gem\\target\\dependency\\glassfish\\pkg\\GlassFish-10.0.0-java.gem to C:\\Users\\Arun Gupta\\.m2\\repository\\org\\glassfish\\distributions\\GlassFish-Gem\\10.0-SNAPSHOT\\GlassFish-Gem-10.0-SNAPSHOT.gem
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESSFUL
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 2 minutes 2 seconds
      [INFO] Finished at: Fri Nov 16 17:56:12 PST 2007
      [INFO] Final Memory: 11M/20M
      [INFO] ------------------------------------------------------------------------

      The Gem is available in target\\dependency\\glassfish\\pkg directory.
  3. Install the Gem
    1. Change to the directory where the Gem is available

      cd target\\dependency\\glassfish\\pkg
    2. Install the Gem as:

      C:\\testbed\\ruby\\jruby-1.0.2\\bin\\jruby -S gem install GlassFish-10.0.0-java.gem
      Successfully installed GlassFish, version 10.0.0

And use it!

Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.

Technorati: totd v3 jruby ruby rubyonrails glassfish gem jrubyonglassfish

Wednesday Nov 14, 2007

Mephisto with GlassFish v3 Gem

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 to deploy Mephisto using GlassFish v3 Gem.

Here are the exact steps:

  1. Install and Configure JRuby 1.0.2. The GlassFish v3 Gem does not work on Windows (JRUBY-1549) with JRuby 1.0.2 and you need to use the JRuby trunk workaround.
    1. Download and Unzip JRuby1.0.2 (lets say JRUBY_HOME).
    2. Include 'JRUBY_HOME/bin' in your environment PATH.
    3. Install Rails (with all dependencies) in JRuby installation by giving the command:

      C:\\workspaces\\jruby-trunk>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
    4. Install ActiveRecord-JDBC as shown below:

      C:\\workspaces\\jruby-trunk>bin\\jruby -S gem install activerecord-jdbc -y --no-rdoc --no-ri
      Need to update 1 gems from http://gems.rubyforge.org
      .
      complete
      Successfully installed ActiveRecord-JDBC-0.5
  2. Download and Install GlassFish V3 Gem.
  3. Install and Configure Database
    1. Download and install MySQL Community Server 5.0 (lets say MYSQL_HOME).
    2. Start MySQL database by giving the command 'mysqld-nt --user root --console' in MYSQL_HOME/bin directory on Windows or './bin/mysqld_safe' from MYSQL_HOME directory on Unix flavors.
    3. In a different shell window, create a database and grant privileges by giving the following commands:
       
      C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin>mysqladmin --u root create mephisto_development

      C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin>mysql -u root
      Welcome to the MySQL monitor. Commands end with ; or \\g.
      Your MySQL connection id is 2
      Server version: 5.0.45-community-nt MySQL Community Edition (GPL)

      Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.

      mysql> grant all on mephisto_development.\* to arun@localhost identified by 'noway';
      Query OK, 0 rows affected (0.00 sec)

      mysql> flush privileges;
      Query OK, 0 rows affected (0.00 sec)

      mysql> quit;
      Bye
  4. Install and Configure Mephisto
    1. Download and Unzip Mephisto 0.7.3.
    2. Install Mephisto as described here. The two steps are summarized below for convenience:
      1. Copy 'MEPHISTO_HOME/config/database.example.yml' to 'MEPHISTO_HOME/config/database.yml'. There is no need to specify the JDBC adapter ActiveRecord 0.5 onwards and that allows to use the default database configuration file.
      2. Bootstrap the development database using the command:

        C:\\testbed\\mephisto-0.7.3>jruby -S rake db:bootstrap -J-DRAILS_ENV=development

        and that shows the following output in the console:

        (in C:/testbed/mephisto-0.7.3)
        mkdir -p C:/testbed/mephisto-0.7.3/config/../log
        -- create_table("assets", {:force=>true})
        -> 0.3330s
        -- create_table("assigned_sections", {:force=>true})
        -> 0.2000s
        -- create_table("cached_pages", {:force=>true})
        -> 0.2980s
        -- create_table("content_versions", {:force=>true})
        -> 0.2130s
        -- create_table("contents", {:force=>true})
        -> 0.2190s
        -- create_table("events", {:force=>true})
        -> 0.2680s
        -- create_table("memberships", {:force=>true})
        -> 0.1890s
        -- create_table("sections", {:force=>true})
        -> 0.1500s
        -- create_table("sessions", {:force=>true})
        -> 0.1200s
        -- add_index("sessions", ["session_id"], {:name=>"sessions_session_id_index"})
        -> 0.3220s
        -- create_table("sites", {:force=>true})
        -> 1.1240s
        -- add_index("sites", ["host"], {:name=>"index_sites_on_host"})
        -> 0.3490s
        -- create_table("taggings", {:force=>true})
        -> 0.1950s
        -- create_table("tags", {:force=>true})
        -> 0.1840s
        -- create_table("users", {:force=>true})
        -> 0.2750s
        -- initialize_schema_information()
        -> 0.2740s
        -- columns("schema_info")
        -> 0.0170s
        copied default theme to C:/testbed/mephisto-0.7.3/config/../themes/site-1...

        ================================================================================

        Thank you for trying out Mephisto 0.7.3: Noh-Varr Edition!

        Now you can start the application with script/server, visit
        http://mydomain.com/admin, and log in with admin / test.

        For help, visit the following:
        Official Mephisto Site - http://mephistoblog.com
        The Mephisto Community Wiki - http://mephisto.stikipad.com/
        The Mephisto Google Group - http://groups.google.com/group/MephistoBlog
  5. Deploy Mephisto on GlassFish v3 Gem as shown below:

    C:\\testbed>\\workspaces\\jruby-trunk\\bin\\jruby -S glassfish_rails mephisto-0.7.3

    And that shows the following output in the console:

    Nov 14, 2007 6:37:51 PM com.sun.enterprise.v3.services.impl.GrizzlyAdapter postConstruct
    INFO: Listening on port 8080
    Nov 14, 2007 6:37:51 PM com.sun.enterprise.v3.services.impl.DeploymentService postConstruct
    INFO: Supported containers : php,phobos,jruby,web
    Nov 14, 2007 6:37:52 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init>
    INFO: New Servicing page from: C:\\testbed\\mephisto-0.7.3\\public
    Nov 14, 2007 6:38:00 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 9054 ms
  6. Mephisto is now deployed at http://localhost:8080/mephisto-0.7.3



    and shows the following output in GlassFish console:

    Nov 14, 2007 6:24:08 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO:

    Processing MephistoController#dispatch (for 127.0.0.1 at 2007-11-14 18:24:08) [GET]

    Nov 14, 2007 6:24:08 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Parameters: {"action"=>"dispatch", "controller"=>"mephisto", "path"=>[]}

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mSQL (0.001000)←[0m ←[0;1mSET SQL_AUTO_IS_NULL=0←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;35;1mSite Columns (0.046000)←[0m ←[0mSHOW FIELDS FROM sites←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mSite Load (0.010000)←[0m ←[0;1mSELECT \* FROM sites WHERE (sites.`host` = 'localhost') LIMIT 1←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;35;1mSite Load (0.017000)←[0m ←[0mSELECT \* FROM sites ORDER BY id LIMIT 1←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mSection Columns (0.010000)←[0m ←[0;1mSHOW FIELDS FROM sections←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;35;1mSection Load (0.005000)←[0m ←[0mSELECT \* FROM sections WHERE (sections.site_id =1) AND (sections.`path` = '') LIMIT 1←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mArticle Columns (0.024000)←[0m ←[0;1mSHOW FIELDS FROM contents←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;35;1mUser Columns (0.013000)←[0m ←[0mSHOW FIELDS FROM users←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mArticle Load Including Associations (0.027000)←[0m ←[0;1mSELECT contents.`id` AS t0_r0, contents.`article_id` AS t0_r1, contents.`user_id` AS t0_r2, contents.`title` AS t0_r3, contents.`permalink` AS t0_r4, contents.`excerpt` AS t0_r5, contents.`body` AS t0_r6, contents.`excerpt_html` AS t0_r7, contents.`body_html` AS t0_r8, contents.`created_at` AS t0_r9, contents.`updated_at` AS t0_r10, contents.`published_at` AS t0_r11, contents.`type` AS t0_r12, contents.`author` AS t0_r13, contents.`author_url` AS t0_r14, contents.`author_email` AS t0_r15, contents.`author_ip` AS t0_r16, contents.`comments_count` AS t0_r17, contents.`updater_id` AS t0_r18, contents.`version` AS t0_r19, contents.`site_id` AS t0_r20, contents.`approved` AS t0_r21, contents.`comment_age` AS t0_r22, contents.`filter` AS t0_r23, contents.`user_agent` AS t0_r24, contents.`referrer` AS t0_r25, users.`id` AS t1_r0, users.`login` AS t1_r1, users.`email` AS t1_r2, users.`crypted_password` AS t1_r3, users.`salt` AS t1_r4, users.`activation_code` AS t1_r5, users.`activated_at` AS t1_r6, users.`created_at` AS t1_r7, users.`updated_at` AS t1_r8, users.`deleted_at` AS t1_r9, users.`token` AS t1_r10, users.`token_expires_at` AS t1_r11, users.`filter` AS t1_r12, users.`admin` AS t1_r13 FROM contents LEFT O
    UTER JOIN users ON users.id = contents.user_id INNER JOIN assigned_sections ON contents.id = assigned_sections.article_id WHERE ((assigned_sections.section_id = 1)) AND (contents.published_at <= '2007-11-15 02:24:09' AND contents.published_at IS NOT NULL) AND ( (contents.`type` = 'Article' ) ) ORDER BY contents.published_at desc LIMIT 15←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;35;1mSection Load (0.009000)←[0m ←[0mSELECT \* FROM sections WHERE (sections.site_id =1) ORDER BY position←[0m

    Nov 14, 2007 6:24:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Completed in 1.12200 (0 reqs/sec) | Rendering: 0.00100 (0%) | DB: 0.16200 (14%) | 200 OK [http://localhost/mephisto-0.7.3]

    Nov 14, 2007 6:24:11 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO:

    Processing AssetsController#show (for 127.0.0.1 at 2007-11-14 18:24:11) [GET]

    Nov 14, 2007 6:24:11 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: Parameters: {"ext"=>"css", "dir"=>"stylesheets", "action"=>"show", "controller"=>"assets", "path"=>"main"}

    Nov 14, 2007 6:24:11 PM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: ←[4;36;1mSite Columns (0.030000)←[0m ←[0;1mSHOW FIELDS FROM sites←[0m

    Nov 14, 2007 6:24:11 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: ←[4;35;1mSite Load (0.018000)←[0m ←[0mSELECT \* FROM sites WHERE (sites.`host` = 'localhost') LIMIT 1←[0m

    Nov 14, 2007 6:24:11 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: ←[4;36;1mSite Load (0.011000)←[0m ←[0;1mSELECT \* FROM sites ORDER BY id LIMIT 1←[0m

    Nov 14, 2007 6:24:12 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: Completed in 0.33500 (2 reqs/sec) | Rendering: 0.00100 (0%) | DB: 0.05900 (17%) | 200 OK [http://localhost/mephisto-0.7.3/stylesheets/main.css]

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO:

    Processing AssetsController#show (for 127.0.0.1 at 2007-11-14 18:24:14) [GET]

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: Parameters: {"ext"=>"png", "dir"=>"images", "action"=>"show", "controller"=>"assets", "path"=>"bg"}

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: ←[4;35;1mSite Columns (0.009000)←[0m ←[0mSHOW FIELDS FROM sites←[0m

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: ←[4;36;1mSite Load (0.017000)←[0m ←[0;1mSELECT \* FROM sites WHERE (sites.`host` = 'localhost') LIMIT 1←[0m

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: ←[4;35;1mSite Load (0.007000)←[0m ←[0mSELECT \* FROM sites ORDER BY id LIMIT 1←[0m

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: Sending data bg.png

    Nov 14, 2007 6:24:14 PM sun.reflect.GeneratedMethodAccessor5 invoke
    INFO: Completed in 0.27900 (3 reqs/sec) | Rendering: 0.00000 (0%) | DB: 0.03300 (11%) | 200 OK [http://localhost/mephisto-0.7.3/images/bg.png]
  7. The exact same application can be easily deployed on WEBrick as shown below:

    C:\\testbed\\mephisto-0.7.3>\\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-14 18:17:57] INFO WEBrick 1.3.1
    [2007-11-14 18:17:57] INFO ruby 1.8.5 (2007-11-01) [java]
    [2007-11-14 18:17:58] INFO WEBrick::HTTPServer#start: pid=11245030 port=3000
    127.0.0.1 - - [14/Nov/2007:18:18:11 PST] "GET / HTTP/1.1" 200 1326

    In this case, Mephisto gets deployed at http://localhost:3000 and WEBrick console shows the following:

    - -> /
    127.0.0.1 - - [14/Nov/2007:18:18:14 PST] "GET /stylesheets/main.css HTTP/1.1" 200 3168
    http://localhost:3000/ -> /stylesheets/main.css
    127.0.0.1 - - [14/Nov/2007:18:18:17 PST] "GET /favicon.ico HTTP/1.1" 200 0
    - -> /favicon.ico
    127.0.0.1 - - [14/Nov/2007:18:18:16 PST] "GET /images/bg.png HTTP/1.1" 200 142
    http://localhost:3000/stylesheets/main.css -> /images/bg.png

This shows how a popular Ruby application can be deployed on WEBrick or GlassFish V3 Gem without any change.

Let us know if you have tried other Rails applications on GlassFish v3 by leaving a comment.

Technorati: glassfish mephisto rubyonrails ror jrubyonglassfish v3 gem ruby jruby

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