JRuby on Rails in GlassFish
From JRubyWiki
GlassFish is an open source Java EE 5 application server. Java EE is a long tested deployment environment and by combining the benefits of GlassFish with JRuby, we should be able to provide the best deployment environment for Rails applications. Here are some of the benefits of using GlassFish as the deployment environment for JRuby on Rails applications :
- Use the time tested Java EE deployment platform
- Avoid the complex Mongrel based deployment environment that one has to use to deploy Rails application.
- With the availability of Goldspike one can deploy a war file of your Rails application directly to a GlassFish instance.
- Java EE and Ruby-on-Rails applications can be easily integrated in one container. This allows to host JRuby-on-Rails applications in organizations who have already made investment in Java EE.
- Rails applications can certainly benefit from the out-of-the-box clustering and high-availability support provided by GlassFish.
- Reuse your database connections by using the database connection pooling mechanism provided by GlassFish.
- Last, but not the least, JRuby-on-Rails can leverage the extensive set of Java libraries.
Read details about why GlassFish is a preferred development & deployment environment for deploying Rails applications in an article at Rails powered by GlassFish Application Server.
Contents |
Glassfish v2
In GlassFish v2 we currently support the war mode of deployment for your JRuby on Rails applications. The war can be created from your existing Rails applications by using Warbler.
Setup
Refer to the section titled "GlassFish V2" of the Getting Started Guide.
At the end of these steps ensure that you have the following environment variables defined :
GLASSFISH_ROOT - pointing to the directory where GlassFish V2 is installed
JRUBY_HOME - the jruby version which would point to $GLASSFISH_ROOT/jruby/jruby-1_0_3/jruby-1.0.3.
PATH - add $GLASSFISH_ROOT/bin and $JRUBY_HOME/bin to your existing PATH environment variable.
Create a simple hello application
For those of you would like to deploy their own JRuby on Rails application, skip this section and refer to the next section titled "How to deploy JRuby on Rails applications".
Below you would find steps that would help you create a very simple JRuby on Rails "hello" application using the JRuby version that you have installed using the steps mentioned in the "Setup" section above.
cd $GLASSFISH_ROOT/jruby/samples jruby -S rails hello jruby script/generate controller say message ( to create a controller "say" with a view "message" )
How to deploy JRuby on Rails applications
Let us see how we could deploy this application to GlassFish v2 in both the Standalone Mode and Shared Mode. In the instructions listed below change the directory name if you are trying to deploy your own JRuby on Rails application.
If you already have a war file of your JRuby on Rails application (created using Warbler or Goldspike) then you could directly refer to the section "To deploy the Rails application".
Standalone Mode
- Go the Rails application directory :
cd $GLASSFISH_ROOT/jruby/samples/hello $GLASSFISH_ROOT/lib/ant/bin/ant -f $GLASSFISH_ROOT/jruby/install.xml create-standalone
You would now find a WEB-INF directory under "hello" sample directory which would contain web.xml and 2 directories lib and gems
- Before we do a directory deployment of the sample to Glassfish, ensure that the GlassFish application server is running :
cd .. asadmin start-domain
Note : If the application server is already running the command safely exits
To deploy the Rails application :
cd $GLASSFISH_ROOT/jruby/samples asadmin deploy hello
- Access the following URLs in a browser :
http://localhost:8080/hello/say/message
http://localhost:8080/hello
Shared Mode
For having an application deployed in shared mode, first ensure that you have followed the "Post Installations" of the Getting Started Guide. Please note that the steps have to done only once for a GlassFish installation.
You would now find a WEB-INF directory under "hello" sample directory which would just contain web.xml
- To deploy the Rails application :
cd $GLASSFISH_ROOT/jruby/samples/hello $GLASSFISH_ROOT/lib/ant/bin/ant -f $GLASSFISH_ROOT/jruby/install.xml create-shared
- Access the following URLs in a browser :
http://localhost:8080/hello/say/message
http://localhost:8080/hello
GlassFish v3
GlassFish V3 is the next major release of the GlassFish application server with the focus on modularization, enablement of non Java EE containers, and embedability. As part of GlassFish V3 we have created a gem which would help users to launch their Ruby on Rails (ROR) applications embedded within the JRuby VM space.
Setup
Refer to the the section titled "GlassFish V3" of the Getting Started Guide.
At the end of these steps ensure that you have the following environment variables are defined :
JRUBY_HOME - the jruby version.
PATH - add $JRUBY_HOME/bin to your existing PATH environment variable.
Sample Application
Refer to the instructions provided in the "Sample Application" section of GlassFish V2 to create a very simple "hello" application. The directory name where you create the application would be different. Again for users who would like to use their own application please feel free to do so.
How to deploy JRuby on Rails applications
To deploy a Rails application with GlassFish v3 gem :
cd <directory_that_contains_the_hello_application> jruby -S glassfish_rails hello
That's it! You would see an output similar to the one listed below in the console where you started the Gem:
Jan 4, 2008 3:35:52 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init> INFO: New Servicing page from: /Users/pramodgopinath/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 and ready to accept requests.
Use the following urls to check out the application :
http://localhost:8080/hello
http://localhost:8080/hello/say/message
Success Stories
External Links
GlassFish JRuby Wiki
Rails powered by GlassFish Application Server
Email dev@glassfish.dev.java.net aliasto discuss problems/issues with GlassFish deployments of JRuby on Rails applictions

