Skip to main content

Grails on GlassFish v3 - Embedded or Stand-alone

Posted by arungupta on July 30, 2008 at 7:13 AM PDT



Grails 1.0.3 was href="http://markmail.org/message/ggpt7drhqfxzsynq">released
a few weeks ago. This blog uses the instructions originally
posted href="http://weblogs.java.net/blog/vivekp/archive/2008/05/embedding_glass.html">here
and shows how to deploy a simple Grails application on GlassFish.

  1. Download href="http://grails.org/download/file?mirror=20">Grails 1.0.3
    and unzip.
  2. Download the latest *-overlay.zip from href="http://maven.dyndns.org/2/org/glassfish/scripting/grails-gfv3/">here
    and unzip on your Grails installation as shown:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/grails-1.0.3 > style="font-weight: bold;">unzip
    ~/Downloads/grails-gfv3-1.1-overlay.zip

    Archive: 
    /Users/arungupta/Downloads/grails-gfv3-1.1-overlay.zip

       creating: lib/glassfish-v3/

      inflating:
    lib/glassfish-v3/gf-embedded-api-1.0-alpha-4.jar 

      inflating:
    lib/glassfish-v3/web-all-10.0-build-20080430.jar 

      inflating: lib/grails-gfv3-1.1.jar 

      inflating: scripts/RunAppGf.groovy
  3. Create a sample app as explained in href="http://blogs.sun.com/arungupta/entry/getting_started_with_grails_on">Getting
    Started With Grails on GlassFish.
  4. Run the app using href="http://embedded-glassfish.dev.java.net/">embedded
    GlassFish as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/grails-1.0.3/samples/helloworld > style="font-weight: bold;">grails run-app-gf



    Welcome to Grails 1.0.3 - http://grails.org/

    Licensed under Apache Standard License 2.0

    Grails home is set to: /Users/arungupta/tools/grails-1.0.3



    Base Directory: /Users/arungupta/tools/grails-1.0.3/samples/helloworld

    Note: No plugin scripts found

    Running script
    /Users/arungupta/tools/grails-1.0.3/scripts/RunAppGf.groovy

    Environment set to development

    Starting
    GlassFish embedded server...
        
    [copy] Copying 1 file to
    /Users/arungupta/.grails/1.0.3/projects/helloworld

    Running Grails application..

    Application name : helloworld

    Web App Root
    :/Users/arungupta/tools/grails-1.0.3/samples/helloworld/web-app

    web.xml:/Users/arungupta/.grails/1.0.3/projects/helloworld/resources/web.xml

    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: HK2 initialized in
    620 ms


    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: com.sun.enterprise.naming.impl.ServicesHookup@2aef3499 Init done
    in 646 ms

    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: com.sun.enterprise.v3.server.Globals@3710f32d Init done in 648 ms

    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: com.sun.enterprise.v3.server.SystemTasks@632dc291 Init done in
    655 ms

    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: com.sun.enterprise.v3.services.impl.HouseKeeper@64c3d9c0 Init
    done in 658 ms

    Jul 28, 2008 2:25:38 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO:
    com.sun.enterprise.v3.services.impl.CmdLineParamProcessor@3a151d3b Init
    done in 664 ms

    JMXMP connector server URL = service:jmx:jmxmp://localhost:8888

    Jul 28, 2008 2:25:39 PM
    com.sun.enterprise.v3.services.impl.GrizzlyProxy start

    INFO: Listening on port 8080

    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: com.sun.enterprise.v3.services.impl.GrizzlyService@2ddd5c89
    startup done in 1059 ms

    Jul 28, 2008 2:25:39 PM
    com.sun.enterprise.v3.services.impl.ApplicationLoaderService
    postConstruct

    INFO: loader service postConstruct started at 1217280339578

    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: Application Loader startup done in 1353 ms

    Jul 28, 2008 2:25:39 PM com.sun.enterprise.v3.server.AppServerStartup
    run

    INFO: Glassfish v3 started in 1355 ms

    Jul 28, 2008 2:25:41 PM org.apache.catalina.loader.WebappLoader
    setClassPath

    INFO: Unknown loader org.glassfish.grails.MaskingClassLoader@5cbde5b4
    class org.glassfish.grails.MaskingClassLoader

    Jul 28, 2008 2:25:41 PM com.sun.enterprise.web.WebModuleContextConfig
    authenticatorConfig

    SEVERE: webModuleContextConfig.missingRealm

    [0]
    spring.GrailsWebApplicationContext Refreshing
    org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585:
    display name
    [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585];
    startup date [Mon Jul 28 14:25:44 PDT 2008]; parent:
    org.springframework.web.context.support.XmlWebApplicationContext@631a8160

    [0]
    spring.GrailsWebApplicationContext Bean factory for application context
    [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@4c721585]:
    org.springframework.beans.factory.support.DefaultListableBeanFactory@3e11bc1d

    Server running. Browse to http://localhost:8080/helloworld


  5. Browsing to "http://localhost:8080/helloworld" shows:



    src="http://blogs.sun.com/arungupta/resource/images/grails103-helloworld-default-output.png">

  6. Create a controller


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/grails-1.0.3/samples/helloworld > style="font-weight: bold;">grails create-controller home



    Welcome to Grails 1.0.3 - http://grails.org/

    Licensed under Apache Standard License 2.0

    Grails home is set to: /Users/arungupta/tools/grails-1.0.3



    Base Directory: /Users/arungupta/tools/grails-1.0.3/samples/helloworld

    Note: No plugin scripts found

    Running script
    /Users/arungupta/tools/grails-1.0.3/scripts/CreateController.groovy

    Environment set to development

         [copy] Copying 1 file to
    /Users/arungupta/tools/grails-1.0.3/samples/helloworld/grails-app/controllers

    Created Controller for Home

        [mkdir] Created dir:
    /Users/arungupta/tools/grails-1.0.3/samples/helloworld/grails-app/views/home

         [copy] Copying 1 file to
    /Users/arungupta/tools/grails-1.0.3/samples/helloworld/test/integration

    Created ControllerTests for Home
  7. Edit the generated controller in
    "grails-app/controllers/HomeController.groovy" such that it
    looks like:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    class HomeController {



        def index = {

           
    render "Grails using embedded GlassFish!"

        }

    }
  8. Refresh the web page in the browser and it looks like:



    src="http://blogs.sun.com/arungupta/resource/images/grails103-helloworld-with-1controller.png">



    and clicking on "HomeController" shows the output as:



    src="http://blogs.sun.com/arungupta/resource/images/grails103-helloworld-controller-output.png">

More details about GlassFish embedding in Grails are available href="http://weblogs.java.net/blog/vivekp/archive/2008/05/embedding_glass.html">here.



This application can also be deployed on stand-alone href="http://blogs.sun.com/arungupta/entry/screencast_24_getting_started_with">GlassFish
v3 Technology Preview 2 as href="http://blogs.sun.com/arungupta/entry/getting_started_with_grails_on">explained
here.
href="http://blogs.bytecode.com.au/glen/2008/07/24/grails--jetty--glassfish-and-jndi-data-sources.html">This
blog explains how to configure JNDI resources for a Grails
application and I plan to explore that in upcoming days.



Once the Servlet engine in Grails is made configurable then GlassFish
can be used as the target deployment
platform from "run-app" script.



NetBeans
6.5 M1
provide extensive support on Grails application
development - details are href="http://docs.codehaus.org/display/GRAILS/NetBeans+Integration">available
here.



Technorati: grails
glassfish
v3 href="http://technorati.com/tag/embedded">embedded
netbeans

Related Topics >>

Comments

Luigi, I think you should be able to submit your feedback at: http://developers.sun.com/contact/feedback.jsp?&category=j2me&mailsubjec...

i'm sorry to disturb You. I've a problem with J2ME Wireless Toolkit 2.2 please, can you tell me who can help me? thanks Luigi