Exit Print View

Sun GlassFish Enterprise Server v3 Scripting Framework Guide

  This Document Entire Library
Print View

Document Information

Preface

1.  Using JRuby on Rails With Sun GlassFish Enterprise Server

Introduction to JRuby and Rails on Sun GlassFish Enterprise Server

What Is Ruby on Rails ?

What Is JRuby ?

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

To Install Rails Gem on JRuby

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

GlassFish v3 Gem

To Install the GlassFish v3 Gem

To Run a Rails Application on GlassFish v3 Gem

To Deploy and Run the Database-Backed Web Application

Using GlassFish v3 Gem CLI

Introduction to Warbler

What Is Warbler ?

Creating and Deploying a Simple Rails Application with Warbler

To Create a Rails Application

To Deploy the WAR File

Further Information

2.  Developing Grails Applications

3.  Jython on Django

4.  Scala and Lift

5.  PHP

GlassFish v3 Gem

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

To install the GlassFish v3 Gem on your JRuby standalone instance, use the following procedure:

  1. Download and install JRuby according to the instructions in To Install JRuby as Standalone.

  2. Install Rails Gem according to the instructions in To Install Rails Gem on JRuby

  3. Run the Gem installer to install the GlassFish v3 Gem:

    jruby -S gem install glassfish

  4. Start your server with the following command:

    jruby -S glassfish

To Run a Rails Application on GlassFish v3 Gem

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.

  1. Change to the directory where a sample application has been created. For example:

    cd /jruby-apps

  2. Deploy the previously created hello application:

    jruby -S glassfish helloV3

  3. 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.

To Deploy and Run the Database-Backed Web Application

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.

  1. Change to /books directory.

  2. Deploy the application to the GlassFish v3 Gem by running the following command:

    jruby -S glassfish books
  3. 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.

  4. Add records to the table by clicking the New book link on the index.html page.

  5. Enter the data for book on the new.html page and click Create.

Using GlassFish v3 Gem CLI

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