Oracle GlassFish Server 3.0.1 Scripting Framework Guide

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 Oracle GlassFish Server 3.0.1 that runs as part of JRuby instance.

When you install the GlassFish v3 Gem on JRuby, you have a Oracle 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.

ProcedureTo 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 and Rails according to the instructions in To Install JRuby in Standalone Mode.

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

    jruby -S gem install glassfish
  3. Start your server with the following command:

    jruby -S glassfish

ProcedureTo 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 GlassFish 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:


    You should now see the following message in your browser window:

    Welcome to JRuby on Rails on the Oracle GlassFish Server!

    Note that the GlassFish v3 Gem runs on port 3000 and not the default port 8080.

ProcedureTo 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 GlassFish Server using directory-based deployment, as described in To Deploy a Rails Application as a Directory Using the asadmin Command.

  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:


    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 server. You can change the configuration options either by using GlassFish Server 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 Server configuration file generated by the following command:

jruby -S gfrake config