Miles to go …

March 18, 2009

TOTD #75: Getting Started with Grails using GlassFish v3 Embedded

Filed under: glassfish, grails, totd — arungupta @ 11:45 pm

For a change, this blog entry is talking about something that exists for a while now :)

Basically, I wanted to setup a demo environment for Grails and GlassFish v3 Prelude on my machine and so decided to dcument the steps along the process. More detailed steps with explanation are available on GlassFish/Grails Getting Started Wiki.

  1. Download and unzip GlassFish v3 Prelude.
  2. Run GlassFish Update Center to install the Grails module as shown:
    ~/demos/glassfishv3-prelude >./bin/updatetool

    The software needed for this command (updatetool) is not installed.

    If you choose to install Update Tool, your system will be automatically
    configured to periodically check for software updates. If you would like
    to configure the tool to not check for updates, you can override the
    default behavior via the tool’s Preferences facility.

    When this tool interacts with package repositories, some system information
    such as your system’s IP address and operating system type and version
    is sent to the repository server. For more information please see:

    http://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2

    Once installation is complete you may re-run this command.

    Would you like to install Update Tool now (y/n): y

    Install image: /Users/arungupta/demos/glassfishv3-prelude/bin/..
    Installing pkg packages.
    Installing: [pkg:/[email protected],0-15.1269:20081008T212532Z, pkg:/[email protected],0-15.1269:20081008T212544Z]
    Installing updatetool packages.
    Installing: [pkg:/[email protected],0-15.1269:20081008T212613Z, pkg:/[email protected],0-15.1269:20081008T212630Z]
    Registering notifier: Already registered.
    Initialization complete.

    Software successfully installed. You may now re-run this command (updatetool).

  3. Now run the Update Center again to see a screen as shown below:

    Select “GlassFish support for Grails Framework” and click on “Install” to install the module locally. This creates a new directory “grails” in your GlassFish v3 Prelude directory and install Grails 1.0.4 there.

  4. Set environment variables as:

    ~/demos/glassfishv3-prelude/glassfish/grails >export GRAILS_HOME=~/demos/glassfishv3-prelude/glassfish/grails
    ~/demos/glassfishv3-prelude/glassfish/grails >export PATH=$GRAILS_HOME/bin:$PATH

  5. Create a template application as:
    ~/demos/glassfishv3-prelude/glassfish/grails/samples >grails create-app bookstore

    Welcome to Grails 1.0.4 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails

    Base Directory: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples
    Note: No plugin scripts found
    Running script /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/scripts/CreateApp.groovy
    Environment set to development
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/src
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/src/java
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/src/groovy
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/controllers
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/services
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/domain
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/taglib
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/utils
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/views
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/views/layouts
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/i18n
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/conf
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/test
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/test/unit
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/test/integration
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/scripts
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/js
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/css
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/images
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/META-INF
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/lib
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/conf/spring
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/conf/hibernate
    [propertyfile] Creating new property file: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/application.properties
         [copy] Copying 2 files to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
    &nbsp
    ;    [copy] Copied 1 empty directory to 1 empty directory under /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
         [copy] Copying 2 files to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/WEB-INF
         [copy] Copying 5 files to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/WEB-INF/tld
         [copy] Copying 28 files to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app
         [copy] Copying 18 files to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
    [propertyfile] Updating property file: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/application.properties
    Created Grails Application at /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore

  6. Create a domain specific class as:
    ~/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore >grails create-domain-class book

    Welcome to Grails 1.0.4 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails

    Base Directory: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
    Note: No plugin scripts found
    Running script /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/scripts/CreateDomainClass.groovy
    Environment set to development
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/domain
    Created Domain Class for Book
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/test/integration
    Created Tests for Book

  7. Add attributes to the domain class by editing “grails-app/domain/Book.groovy” such that it looks like:
    class Book {
      String title
      String author
    }

  8. Create a new controller as:
    ~/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore >grails create-controller Book

    Welcome to Grails 1.0.4 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails

    Base Directory: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
    Note: No plugin scripts found
    Running script /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/scripts/CreateController.groovy
    Environment set to development
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/controllers
    Created Controller for Book
        [mkdir] Created dir: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/views/book
         [copy] Copying 1 file to /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/test/integration
    Created ControllerTests for Book

  9. Edit the generated controller in “grails-app/controller/BookController.groovy” to specify scaffold for the domain class. It looks like:
    class BookController {
        def scaffold = Book
    }
  10. Run the app as shown below:
    ~/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore >grails run-app

    Welcome to Grails 1.0.4 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails

    Base Directory: /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore
    Note: No plugin scripts found
    Running script /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/scripts/RunApp.groovy
    Environment set to development
    Starting GlassFish embedded server…    [mkdir] Created dir: /Users/arungupta/.grails/1.0.4/projects/bookstore/classes
      [groovyc] Compiling 8 source files to /Users/arungupta/.grails/1.0.4/projects/bookstore/classes
        [mkdir] Created dir: /Users/arungupta/.grails/1.0.4/projects/bookstore/resources/grails-app/i18n
    [native2ascii] Converting 11 files from /Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/grails-app/i18n to /Users/arungupta/.grails/1.0.4/projects/bookstore/resources/grails-app/i18n
         [copy] Copying 1 file to /Users/arungupta/.grails/1.0.4/projects/bookstore/classes
         [copy] Copying 1 file to /Users/arungupta/.grails/1.0.4/projects/bookstore/resources
         [copy] Copying 1 file to /Users/arungupta/.grails/1.0.4/projects/bookstore
    Running Grails application..
    Application name : bookstore
    Web App Root :/Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app
    web.xml:/Users/arungupta/.grails/1.0.4/projects/bookstore/resources/web.xml
    Mar 18, 2009 10:19:09 PM CommonClassLoaderManager Skipping creation of CommonClassLoader as there are no libraries available
    INFO: urls = []
    no resource bundle found for version, using default GlassFish version
    Mar 18, 2009 10:19:09 PM AppServerStartup run
    INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
    Mar 18, 2009 10:19:09 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 8080
    Mar 18, 2009 10:19:10 PM org.glassfish.admin.mbeanserver.ConnectorStartupService$ConnectorsStarterThread startConnector
    INFO: Started JMXConnector, JMXService URL = service:jmx:rmi:///jndi/rmi://192.168.1.145:8686/jmxrmi
    Mar 18, 2009 10:19:10 PM com.sun.enterprise.v3.admin.adapter.AdminEndpointDecider setGuiContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Mar 18, 2009 10:19:10 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3 Prelude startup time : Embedded(418ms) st
    artup services(887ms) total(1305ms)

    Mar 18, 2009 10:19:10 PM com.sun.enterprise.web.WebContainer createHttpListener
    INFO: Created HTTP listener http-listener-1 on port 8080
    Mar 18, 2009 10:19:10 PM com.sun.enterprise.web.WebContainer createHosts
    INFO: Created virtual server server
    Mar 18, 2009 10:19:11 PM org.apache.catalina.loader.WebappLoader setClassPath
    INFO: Unknown loader org.glassfish.grails.MaskingClassLoader@3b948e75 class org.glassfish.grails.MaskingClassLoader
    Mar 18, 2009 10:19:12 PM org.apache.catalina.loader.WebappLoader setClassPath
    INFO: Unknown loader org.glassfish.internal.api.DelegatingClassLoader@191fa2af class org.glassfish.internal.api.DelegatingClassLoader
    Mar 18, 2009 10:19:12 PM org.apache.catalina.core.ApplicationContext log
    INFO: PWC1412: WebModule[/bookstore] ServletContext.log():Set web app root system property: ‘bookstore-development-0.1′ = [/Users/arungupta/demos/glassfishv3-prelude/glassfish/grails/samples/bookstore/web-app/]
    Mar 18, 2009 10:19:12 PM org.apache.catalina.core.ApplicationContext log
    INFO: PWC1412: WebModule[/bookstore] ServletContext.log():Initializing log4j from [file:/Users/arungupta/.grails/1.0.4/projects/bookstore/resources/log4j.properties]
    Mar 18, 2009 10:19:12 PM org.apache.catalina.core.ApplicationContext log
    INFO: PWC1412: WebModule[/bookstore] ServletContext.log():Initializing Spring root WebApplicationContext
    [0] spring.GrailsWebApplicationContext Refreshing org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@430b4506: display name [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@430b4506]; startup date [Wed Mar 18 22:19:14 PDT 2009]; parent: org.springframework.web.context.support.XmlWebApplicationContext@6ceb51a8
    [0] spring.GrailsWebApplicationContext Bean factory for application context [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@430b4506]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1f43243e
    Mar 18, 2009 10:19:17 PM org.apache.catalina.core.ApplicationContext log
    INFO: PWC1412: WebModule[/bookstore] ServletContext.log():Initializing Spring FrameworkServlet ‘grails’
    Mar 18, 2009 10:19:17 PM com.sun.enterprise.web.WebApplication start
    INFO: Loading application bookstore at /bookstore
    Server running. Browse to http://localhost:8080/bookstore

    Notice, here GlassFish v3 Embedded Server is used for running the application. It is now accessible at “http://localhost:8080/bookstore” and looks like:

  11. Clicking on the “BookController” shows:

  12. Click on “New Book” to add a new book as:

  13. Each entry can be updated/deleted after clicking on “Create” …

    or “Book List” as shown below:

In a matter of few minutes, we created a simple Grails scaffold that runs using GlassFish v3 Embedded Server.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all tips is available here.

Technorati: totd glassfish v3 grails embedded prelude

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. Getting Started with Grails on GlassFish
  2. TOTD #30: CRUD Application using Grails – Hosted on Jetty and HSQLDB
  3. Grails on GlassFish v3 – Embedded or Stand-alone
  4. TOTD #31: CRUD Application using Grails – Hosted on GlassFish and MySQL
  5. TOTD #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3

1 Comment »

  1. Good posting! more professional web templates at <a href="http://www.itemplatez.com"&gt;itemplatez.com&lt;/a&gt;... its a
    <a href="http://www.drivecrank.com"&gt;easy&lt;/a&gt; download.

    Comment by hockmanli — April 1, 2009 @ 2:24 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress