1. Using JRuby on Rails With Sun GlassFish Enterprise Server
Introduction to JRuby and Rails on Sun GlassFish Enterprise Server
JRuby on Rails, the Sun GlassFish Enterprise Server v3, and the GlassFish v3 Gem
Installation and Configuration of JRuby
To Install JRuby and Rails from Update Center
To Install JRuby as Standalone
Enterprise Server v3 JRuby Container Configuration
Configuring JRuby Container Through Asadmin CLI
Configuring JRuby Runtime Pool
Configuring JRuby Container Through Administration Console
To Configure JRuby Container from Administration Console
Creating a Simple Rails Application
To Create the hello Application
To Create the Controller and the View
To Pass Data From the Controller to the View
To Use Rails Without a Database
Deploying and Running a Rails Application
To Deploy the Rails Application as a Directory
Accessing a Database From a Rails Application
To Set Up the MySQL Database Server
To Create a Database-Backed Rails Application
Accessing Java Libraries From a Rails Application
To Create the Rails Application That Accesses Java Libraries
To Create the Views That Display the Images Generated by Java2D Code
To Add Java2D Code to a Rails Controller
To Run a Rails Application That Uses Java 2D Code
Monitor Rails Applications on Enterprise Server v3
Monitoring for JRuby Container
Viewing JRuby Container Statistics
To Install the GlassFish v3 Gem
To Run a Rails Application on GlassFish v3 Gem
Creating and Deploying a Simple Rails Application with Warbler
Another way to work with JRuby is to install the GlassFish v3 Gem on a JRuby standalone instance. The GlassFish v3 Gem is just a lightweight version of the Sun GlassFish Enterprise Server v3 that runs as part of JRuby instance.
When you install the GlassFish v3 Gem on JRuby, you have a Sun GlassFish instance embedded in the JRuby virtual machine. This gives you a more complete development environment because you have everything you need for JRuby on Rails applications running inside the JRuby virtual machine in addition to everything you need from the GlassFish Server to create web applications.
To install the GlassFish v3 Gem on your JRuby standalone instance, use the following procedure:
Download and install JRuby according to the instructions in To Install JRuby as Standalone.
Install Rails Gem according to the instructions in To Install Rails Gem on JRuby
Run the Gem installer to install the GlassFish v3 Gem:
jruby -S gem install glassfish
Start your server with the following command:
jruby -S glassfish
You can also run your JRuby on Rails application on the embedded
GlassFish v3 Gem. Create a simple Rails application as described in Creating a Simple Rails Application. Instead
of deploying it to the Enterprise Server, use the GlassFish v3 Gem to
run that application as described in the following task.
Change to the directory where a sample application has been created. For example:
cd /jruby-apps
Deploy the previously created hello application:
jruby -S glassfish helloV3
Run the application using the following URL in your web browser:
http://localhost:3000/home/index
You should now see the following message in your browser window:
Welcome to JRuby on Rails on the Sun GlassFish Enterprise Server!
Note that the GlassFish v3 Gem runs on port 3000 and not the default port 8080.
Creating database-backed web applications was described in To Create a Database-Backed Rails Application. The following task describes running
the created books application on the GlassFish v3 Gem. You can alternatively deploy
it to your regular Enterprise Server using directory-based deployment, as described in
To Deploy the Rails Application as a Directory.
Change to /books directory.
Deploy the application to the GlassFish v3 Gem by running the following command:
jruby -S glassfish books
Run the application in your web browser using the following URL:
http://localhost:3000/books
The opening page says “Listing books” and has an empty table, meaning that there are no book records in the database yet. To add book records to the table, do the next step.
Add records to the table by clicking the New book link on the index.html page.
Enter the data for book on the new.html page and click Create.
The GlassFish v3 Gem offers several commands to configure the GlassFish server. You can change the configuration options either by using GlassFish command line or by modifying the glassfish.yml file. You view these options by using the following command:
glassfish -h
The options include runtimes, runtimes-min, runtimes-max, and also a configuration option to create a configuration file for GlassFish Server.
You can create a glassfish.yml file which is a default GlassFish configuration file generated by the following command:
jruby -S gfrake config