Thursday Sep 17, 2009

TOTD #104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct

GlassFish v3 is opening up new frontiers by allowing to easily deploy Rails, Grails and Django applications, in addition to Java EE, without any additional packaging. You can even write a custom container to support new types of applications. Numerous entries on this blog have talked about how to deploy Rails applications on GlassFish v3. This Tip Of The Day (TOTD) will recap them and, once again, demonstrate how to easily get started with deploying some popular open source Rails applications on GlassFish v3.

Lets prepare a GlassFish v3 build for deploying Rails applications. This blog is going to use 9/16 nightly but you should pick the latest nightly or promoted.

  1. Unzip the downloaded bundle as:
    ~/tools/glassfish/v3/9-16 >unzip ~/Downloads/glassfish-v3-b64-09_16_2009.zip
  2. Configure JRuby/Rails in GlassFish v3 - JRuby/rails can be configured three different ways - use a previously installed JRuby/Rails directory, install JRuby/Rails module using the graphical Update Center or the "pkg" binary. This Update Center module comes packaged with JRuby 1.3.1, Rails 2.3.2 and some other useful gems. Pick the option you are most comfortable with and use it for your GlassFish installation.
    1. Configure previously installed JRuby/Rails directory as:
      ~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin create-jvm-options -Djruby.home=/Users/arungupta/tools/jruby
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password >
      created 1 option(s)
      Command create-jvm-options executed successfully.

      That's it!
    2. Install JRuby/Rails module using graphical Update Tool
      1. The graphical Update Tool tool can be invoked as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/updatetool
        
        The software needed for this command (updatetool) is not installed.
        
        If you choose to install Update Tool, your system will be automatically
        configured to periodically check for software updates. If you would like
        to configure the tool to not check for updates, you can override the
        default behavior via the tool's Preferences facility.
        
        When this tool interacts with package repositories, some system information
        such as your system's IP address and operating system type and version
        is sent to the repository server. For more information please see:
        
        http://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2
        
        Once installation is complete you may re-run this command.
        
        Would you like to install Update Tool now (y/n): y
        
        Proxy: Using system proxy settings.
        Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3
        Installing pkg packages.
        Installing updatetool packages.
        Registering notifier: Already registered.
        Initialization complete.
        
        Software successfully installed. You may now re-run this command (updatetool).
      2. The first invocation of the command installs the Update Tool and the second invocation shows the following screen after "JRuby on GlassFish" module is selected:


        Click on green button in the top left to install the module and it picks up the dependencies as well as shown below:


        Click on "Install" to start the installation and click on "Accept" to accept the license.
      3. Close the Update Tool window once the installation is completed. The module creates "glassfish/jruby" directory.
    3. Install JRuby/Rails module using "pkg" binary
      1. Install the JRuby/Rails bits using the "pkg" binary. Invoke the command as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg

        The software needed for this command (pkg) is not installed. When this tool interacts with package repositories, some system information such as your system's IP address and operating system type and version is sent to the repository server. For more information please see: http://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2 Once installation is complete you may re-run this command. Would you like to install this software now (y/n): y Proxy: Using system proxy settings. Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3 Installing pkg packages. Initialization complete. Software successfully installed. You may now re-run this command (pkg).
      2. The command "pkg list -a" shows all the modules available for installation and the output looks like:

        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg list -a
        NAME (PUBLISHER)                              VERSION         STATE      UFIX
        ant (contrib.glassfish.org)                   1.7.1-0.6       known      ----
        felix                                         2.0.0-0         installed  ----
        glassfish-appclient                           3.0-65          installed  ----
        glassfish-cmp                                 3.0-65          installed  ----
        
        . . .
        
        jersey-docs-and-examples                      1.1.2-1.0       known      ----
        jmaki (contrib.glassfish.org)                 1.8.1-2.0       known      ----
        jruby                                         1.3.1-1.1       known      ----
        jruby (contrib.glassfish.org)                 1.2.0-1.1       known      u---
        jruby-gems (contrib.glassfish.org)            2.3.2-1.1       known      ----
        jython-container (contrib.glassfish.org)      0.5.3-1.0       known      ----
        jython-runtime (contrib.glassfish.org)        2.5.0-1.0       known      ----
        metro                                         2.0-19          installed  ----
        
        . . .
        
        updatetool                                    2.3.0-36.2403   known      ----
        updatetool (contrib.glassfish.org)            2.2.2-30.2311   known      u---
        wxpython2.8-minimal                           2.8.10.1-36.2403 known      ----
        wxpython2.8-minimal (contrib.glassfish.org)   2.8.8-30.2311   known      u---
      3. Start the installation of "jruby" module as:

        ~/tools/glassfish/v3/9-17/glassfishv3 >./bin/pkg install jruby
        DOWNLOAD                                  PKGS       FILES    XFER (MB)
        Completed                                  2/2 14810/14810    37.0/37.0
        
        PHASE                                        ACTIONS
        Install Phase                            17273/17273
  3. Redmine on GlassFish - Redmine is an open source project management web application. The simplified steps to deploy Redmine on GlassFish v3 are given below (also on GlassFish Gem and on GlassFish v3 TP2):
    1. Download and unzip Redmine 0.8.5 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml.new >config/database.yml
    3. Create the database manually as "sudo mysqladmin create redmine_development". "db:create" fails because of JRUBY-3502.
    4. Migrate the database as "db:migrate".
    5. Deploy the application as:
      ~/samples/jruby/redmine >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy redmine-0.8.5
       Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password>
      Command deploy executed successfully.
    6. Here are some snapshots from the deployed application:





  4. Typo on GlassFish - Typo is the oldest Ruby on Rails blogware. The simplified steps to deploy Typo on GlassFish v3 are given below (also on GlassFish Prelude):
    1. Download and unzip Typo 5.3 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml.example >config/database.yml
    3. Create the database manually as "sudo mysqladmin create typo_dev". "db:create" fails because of JRUBY-3502.
    4. Typo runs using Rails 2.2.2 so lets install Rails 2.2.2 so lets install Rails 2.2.2 as:
      ~/samples/jruby/typo/typo-5.3 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install rails -v 2.2.2
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
      Successfully installed activesupport-2.2.2
      Successfully installed activerecord-2.2.2
      Successfully installed actionpack-2.2.2
      Successfully installed actionmailer-2.2.2
      Successfully installed activeresource-2.2.2
      Successfully installed rails-2.2.2
      6 gems installed
      Installing ri documentation for activesupport-2.2.2...
      Installing ri documentation for activerecord-2.2.2...
      Installing ri documentation for actionpack-2.2.2...
      Installing ri documentation for actionmailer-2.2.2...
      Installing ri documentation for activeresource-2.2.2...
      Installing ri documentation for rails-2.2.2...
      Installing RDoc documentation for activesupport-2.2.2...
      Installing RDoc documentation for activerecord-2.2.2...
      Installing RDoc documentation for actionpack-2.2.2...
      Installing RDoc documentation for actionmailer-2.2.2...
      Installing RDoc documentation for activeresource-2.2.2...
      Installing RDoc documentation for rails-2.2.2...
    5. Migrate the database as "db:migrate".
    6. Deploy the application as:
      ~/samples/jruby/typo >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy typo-5.3
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password>
      Command deploy executed successfully.
    7. Here are are some snapshots from the deployed application:





  5. Substruct on GlassFish - Substruct is an open source E-Commerce project in Ruby-on-Rails. The simplified steps to deploy Substruct on GlassFish v3 are given below (also on GlassFish v3 Gem):
    1. Download and unzip substruct 1.0 a6 (latest stable release).
    2. Install the required gems as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install RedCloth fastercsv mime-types mini_magick ezcrypto jruby-openssl --no-ri --no-rdoc
    3. Change the database adapter from "mysql" to "jdbcmysql" as:

      ~/samples/jruby/substruct/substruct_rel_1-0-a6>sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml
      >config/database.yml.new
      ~/samples/jruby/substruct/substruct_rel_1-0-a6>mv config/database.yml.new config/database.yml
    4. Create the database manually as "sudo mysqladmin create substruct_development". "db:create" fails because of JRUBY-3502.
    5. Initialize the database as:
      ~/samples/jruby/substruct/substruct_rel_1-0-a6 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S rake substruct:db:bootstrap
    6. Deploy the application as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy substruct_rel_1-0-a6
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password>
      
      Command deploy executed successfully.
    7. Here is a snapshot of the deployed application:

So we deployed Redmine, Typo, and Substruct using JRuby/Rails on GlassFish without any additional packaging. There are several Rails applications deployed in production on GlassFish.

What Rails applications are you deploying on GlassFish ?

Technorati: glassfish v3 rubyonrails jruby redmine typo mephisto substruct

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

Tuesday May 22, 2007

Mephisto on GlassFish V3

This blog shows how Mephisto, a web publishing system based on Ruby on Rails, can be deployed on GlassFish V3 with minimal changes. These detailed steps are derived from the original instructions. Here are the exact steps that I followed:

  1. Download Install GlassFish V3 Technology Preview 1 (lets say GLASSFISH_HOME).
  2. Install and Configure JRuby
    1. Download and Install JRuby1.0 RC2 in 'GLASSFISH_HOME/lib' directory. Rename the installation directory to 'jruby' (lets say JRUBY_HOME).
    2. Include 'JRUBY_HOME/bin' in your environment PATH.
    3. Install Rails and ActiveRecord gems in JRuby installation by giving the command:

      gem install rails -y --no-rdoc
      gem install activerecord-jdbc -y --no-rdoc
    4. Download and Install MySQL/J Connector in a new directory. Copy the JAR file from the main installation directory to 'JRUBY_HOME/lib' directory.
  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. Create a database and grant privileges by giving the following commands:
       
      MYSQL_HOME/bin/mysql -u root
      mysql> create database mephisto character set utf8;
      Query OK, 1 row affected (0.00 sec)

      mysql> grant all on mephisto.\* 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. Rename the installation directory to 'mephisto' (lets say MEPHISTO_HOME) for convenience.
    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'. Change database entries in the file from:

        development:
          adapter: mysql
          database: mephisto_development
          username: root
          password:
          host: localhost


        to

        development:
          adapter: jdbc
          driver: com.mysql.jdbc.Driver
          url: jdbc:mysql://localhost:3306/mephisto
          username: arun
          password: noway
      2. Edit 'MEPHISTO_HOME/config/environment.rb', add the following fragment before "Rails::Initializer.run" statement.

        if RUBY_PLATFORM =~ /java/
          require 'rubygems'
          RAILS_CONNECTION_ADAPTERS = %w(jdbc)
        end
      3. Run 'rake db:bootstrap' to bootstrap the development database. On windows, you may have to invoke this command as 'JRUBY_HOME\\bin\\jruby.bat JRUBY_HOME\\bin\\rake db:bootstrap'.
  5. Start GlassFish V3 by invoking the following command in GLASSFISH_HOME:

    java -jar lib/glassfish-10.0-SNAPSHOT.jar
  6. Deploy the application from 'GLASSFISH_HOME/bin' as:

    asadmin deploy --path MEPHISTO_HOME
  7. Mephisto is now deployed at 'http://localhost:8080/mephisto'.

This shows how a Ruby application, with minimal change, can be deployed on GlassFish V3. This was also shown in the JavaOne 2007 Technical keynote (start @ 8:29 and finish @ 10:50).

I encourage you to try other popular Rails applications on GlassFish and leave your feedback here.

Technorati: glassfish mephisto rubyonrails ror jrubyonglassfish

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
« July 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
31
  
       
Today