Deploying a Ruby on Rails application in GlassFish

There are a few ways a Ruby on Rails(RoR) application could be deployed on a Java EE based application server platform. One of them is to create a WAR file containing the RoR application with the appropriate adapter code between the application server and the ruby application. On how to go about developing and deploying a RoR application on GlassFish - an open source Java EE 5 application server - follow the steps below:

1. Install GlassFish application server
2. Install JRuby
3. Install Rails Framework 'gems install rails -y' (if behind a http proxy, set HTTP_PROXY=http://${http-proxy-host}:${http-proxy-port}/)
4. Install activerecord-jdbc 'gems install activerecord-jdbc'
5. Install database/jdbc driver (for mysql http://mysql.com/)
6. Generate your Ruby on Rails application (http://rubyonrails.org/)
7. Modify database.yaml
       development:
           adapter: jdbc
           driver: com.mysql.jdbc.Driver (for mysql)
           url: jdbc:mysql://${database-hostname}/${db-schema}
           username: ${username}
           password: ${password}
8. Modify environment.rb by adding
       require 'active_record/connection_adapters/jdbc_adapter'
9. Download rails-integration-${version}-SNAPSHOT.jar into the WEB-INF/lib by checking out and building the rails-integration project
svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration
10. Modify the template web.xml(see references below) with the right value of jruby.home
11. Create a WEB-INF directory in the RoR application directory
12. Copy web.xml to WEB-INF and rails-integration-${version}-SNAPSHOT.jar under WEB-INF/lib
13. Jar up the RoR application directory contents as a WAR file

Requests to appropriate context-root of the deployed web application should invoke your Ruby code !

If you'd like to automate the building of a war file:
Edit rails-integration/build.xml and add the following XML snippet
  <property environment="env"/>
  <target name="build-rails-war" depends="jar">
    <delete file="${rails-app-dir}/${rails-app-name}.war"/>
    <mkdir dir="${rails-app-dir}/WEB-INF/lib"/>
    <copy todir="${rails-app-dir}/WEB-INF/lib">
      <fileset file="${maven.build.directory}/${maven.build.final.name}.jar"/>
      <fileset file="${maven.repo.local}/org/jruby/jruby/0.9.1/jruby-0.9.1.jar"/>
      <fileset file="${maven.repo.local}/asm/asm/2.2.2/asm-2.2.2.jar"/>
      <fileset file="${maven.repo.local}/javax/activation/activation/1.1/activation-1.1.jar"/>
    </copy>
    <copy todir="${rails-app-dir}/WEB-INF/">
      <fileset file="samples/scaffold/WEB-INF/web.xml"/>
    </copy>
    <replace file="${rails-app-dir}/WEB-INF/web.xml" token="/usr/local/jruby" value="${env.JRUBY_HOME}"/>
    <jar jarfile="${rails-app-dir}/${rails-app-name}.war" basedir="${rails-app-dir}"/>
  </target>

Make sure JRUBY_HOME is set and run
'ant -Drails-app-dir=${ror-app-dir} -Drails-app-name=${war-file-name} build-rails-war'
${ror-app-dir}/${ror-app-name}.war should be ready for deployment !

All of this is work in progress some of this might change very soon. Thanks to rail-integration developers and the jruby folks !
Comments:

Very exciting! I had some trouble getting the "depot" app from Agile Web Development with Rails working though: undefined method `items' for nil:NilClass I was able to dispatch to rails/info/properties, however, which means that dynamic pages are at least working.

Posted by Charles Oliver Nutter on December 01, 2006 at 05:03 PM PST #

Post a Comment:
Comments are closed for this entry.
About

whacko

Search

Categories
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