Getting Started Using JRuby on the GlassFish<sup>TM</sup> Application Server
IntroductionThe GlassFish application server provides excellent deployment solutions for JRuby on Rails applications. From this guide you can learn how to create a simple Rails application using JRuby and deploy it on the GlassFish application server. Installing JRuby and RailsTo get started creating JRuby on Rails applications, you need to install JRuby and Rails by performing the following steps. Be sure to use the latest versions of JRuby and Rails so that you benefit from the newest features and bug fixes.
Creating a Hello World ApplicationCreate a template application by running the following command:jruby -S rails hello Create a controller and view by performing the following steps:1. Go to the hello directory: cd hello 2. Enter the following command to generate a controller and default view for the hello application: jruby script/generate controller say hello Create a variable in the controller by doing the following:1. Open the controller, say_controller.rb, in a text editor, such as vi: vi app/controllers/say_controller.rb 2. Add the following string to the controller's hello helper method: @hello_string = "v3 Gem is getting polished!" Retrieve the value of @hello_string in the view by doing the following:1. Open the view in a text editor:
vi app/views/say/hello.html.erb
vi app/views/say/hello.rhtml 2. Add the following string at the bottom of the view: <%= @hello_string %> Configure a Database if Using Rails 2.1.0Perform the steps in this section only if you are using Rails 2.1.0. If you are running earlier versions of Rails, such as version 1.2.6, skip this section. In the hello sample, you do not need a database, so you should do one of the following two things:
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
Even though you don't have a model in the hello sample, Rails 2.1.0 expects you to create a database, which you do by running the following command after you have created the scaffold: jruby -S rake db:create This command creates the database, hello_development. Deploy and run Rails on GlassFish gemThe fastest and easiest way to deploy and run your Rails applications is to do so on the GlassFish gem. The GlassFish gem consists of only the GlassFish v3 kernel, Grizzly, and some utilities, thereby resulting in a smaller size a and faster startup time. You only need perform a one-time installation of the GlassFish gem to deploy and run applications on it. Deploy and run Rails on GlassFish v3While the GlassFish gem offers a robust and easy-to-use deployment environment, sometimes you need to use Java<sup>TM</sup> EE features from inside your Rails application and for this you need to deploy the application to the GlassFish v3 server. Deploy and run Rails on Glassfish v2You can deploy a Rails application on the GlassFish v2 application server by packaging it as a web archive (WAR) file. You perform this packaging using Goldspike, which is available with the JRuby on Rails GlassFish v2 UC module. |