Oracle GlassFish Server 3.0.1 Scripting Framework Guide

Creating a Simple Grails Application

To create and run a simple helloworld application, perform the following tasks:

For more information on creating Grails applications, see the Grails Quick Start guide.

ProcedureTo Create the helloworld Application

  1. Change to the as-install/grails/samples directory.

  2. Run the grails create-app helloworld command.

    The grails create-app command creates a helloworld application that you can modify.

ProcedureTo Create the hello Controller

  1. Change to the as-install/grails/samples/helloworld directory.

  2. Run the grails create-controller hello command.

    The grails create-controller command creates a controller file that you can modify in the /grails/samples/helloworld/grails-app/controllers directory:

  3. Edit the generated HelloController.groovy file so that it looks as follows:

    class HelloController {
           def world = {
                    render "Hello World!"
        //def index = { }

ProcedureTo Run a Grails Application Using Standard Deployment

  1. Change to the application directory. For example:

    cd as-install/grails/samples/helloworld
  2. Create the WAR file using the following command:

    grails war

    This command creates a WAR file, helloworld-0.1.war in the helloworld application directory. The WAR file contains all the application's dependencies, and various jar files.

  3. Deploy the WAR file in one of the following ways:

    • In the Administration Console, open the Applications component, go to the Web Applications page, select the Deploy button, and type the path to the WAR file.

      For example:


    • Use the asadmin deploy command from command line to deploy the WAR file. For example:

      asadmin deploy helloworld-0.1.war

      Note –

      Depending on the configuration, you might be prompted for the asadmin password at this time.

  4. To test your application, open http://host:port/war-file-name in your browser.

    Do not include the .war extension. For example:


    You should see a screen that shows the following message:

    Welcome to Grails

    Clicking the HelloController link should change the display to the following message:

    Hello World!
See Also

For details about the Administration Console, see the GlassFish Server online help.

For details about the asadmin deploy command, see the Oracle GlassFish Server 3.0.1 Reference Manual.

For details about the Grails commands, see the Grails Quick Start guide.

For general information about deployment, see the Oracle GlassFish Server 3.0.1 Application Deployment Guide.