Skip to main content

Database-enabled RoR WAR on GlassFish

Posted by arungupta on May 17, 2007 at 7:47 AM PDT

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

Follow up from
here.

In this post I'll show how a Ruby-on-Rails (RoR) application, talking to MySQL database, can be
deployed as a WAR file on GlassFish V2. Here are the
steps I followed:

  1. Create a HelloWorld RoR app talking to MySQL database as described

    here
    .
  2. Expand NetBeans project, expand 'Configuration' and open 'database.yml'.
    Change production database entry from:



    production:

      adapter: mysql

      database: HelloWorld_production

      username: root

      password:

      host: localhost



    to



    production:

      adapter: jdbc

      driver: com.mysql.jdbc.Driver

      url: jdbc:mysql://localhost:3306/helloworld_development

      username: root

      password:




    Notice, even though this is production setting we are using a "development"
    database.
  3. In 'Configuration', 'environment.rb', add



    require 'jdbc_adapter'



    right before



    Rails::Initializer.run do |config|



    On some platforms, this syntax has caused problems. In that case, it may
    alternatively be specified (step
    9
    ) as:
    if RUBY_PLATFORM =~ /java/
           require 'rubygems'
           RAILS_CONNECTION_ADAPTERS = %w(jdbc)
    end
  4. Recreate the WAR file by invoking the command 'rake war:standalone:create' from your application directory.
  5. Drop this WAR file in "domains/domain1/autodeploy"
    directory of your GlassFish instance and you are done!

With this, you've deployed a Ruby-on-Rails application accessing MySQL
database as a WAR file on GlassFish V2.

Technorati:
glassfish
rubyonrails
ror

netbeans

Related Topics >>