Grails on GlassFish v3 - Embedded or Stand-alone


Grails 1.0.3 was released a few weeks ago. This blog uses the instructions originally posted here and shows how to deploy a simple Grails application on GlassFish.
  1. Download Grails 1.0.3 and unzip.
  2. Download the latest \*-overlay.zip from here and unzip on your Grails installation as shown:

    ~/tools/grails-1.0.3 >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 Getting Started With Grails on GlassFish.
  4. Run the app using embedded GlassFish as:

    ~/tools/grails-1.0.3/samples/helloworld >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:


  6. Create a controller

    ~/tools/grails-1.0.3/samples/helloworld >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:

    class HomeController {

        def index = {
            render "Grails using embedded GlassFish!"
        }
    }
  8. Refresh the web page in the browser and it looks like:



    and clicking on "HomeController" shows the output as:

More details about GlassFish embedding in Grails are available here.

This application can also be deployed on stand-alone GlassFish v3 Technology Preview 2 as explained here. 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 available here.

Technorati: grails glassfish v3 embedded netbeans
Comments:

Hi Arun,

Thanks for the post.

I ran into a couple of problems when I tried this. I needed to do the install into tools/grails-1.0.3/grails instead of the tools/grails-1.0.3 directory you mentioned.

After I did that my application ran but there were two issues:

1,I got the following SEVERE messages in the output:

31-Jul-2008 11:25:08 com.sun.enterprise.deployment.io.DeploymentDescriptorFile read
SEVERE: enterprise.deployment.backend.saxParserError
31-Jul-2008 11:25:09 org.apache.catalina.loader.WebappLoader setClassPath
INFO: Unknown loader org.glassfish.grails.MaskingClassLoader@1e965e9 class org.glassfish.grails.MaskingClassLoader
31-Jul-2008 11:25:09 com.sun.enterprise.web.WebModuleContextConfig authenticatorConfig
SEVERE: webModuleContextConfig.missingRealm
31-Jul-2008 11:25:10 org.apache.catalina.core.StandardContext start
SEVERE: PWC1315: Error reading listeners from TLD
javax.servlet.ServletException: PWC3037: Exception processing TLD at resource path /WEB-INF/tld/spring.tld in context /HelloWorld

2, I could access the application, but none of the styling was available.

Any ideas why this might be the case? Anyone else hit these problems?

Thanks,
ngu

Posted by New Grails User on July 30, 2008 at 08:52 PM PDT #

New Grails User,

The install can be done in any directory as long GRAILS_HOME is set correctly.

"SEVERE: webModuleContextConfig.missingRealm" is filed as a bug at:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=4917

I did not see any other SEVERE messages as is evident from the console dump in the entry.

The screen dump shows the Grails image and font rendered properly. If you still see an issue, I recommend file a bug at:

https://glassfish.dev.java.net/servlets/ProjectIssues

Posted by Arun Gupta on July 31, 2008 at 05:24 AM PDT #

Hi Arun,

Thanks for the reply. The problem might not have been clear from the stack trace, but it looks like there is an issue with the spring.tld. The relevant details are included below.

It's a newproject, so I can't understand why I'm getting this problem.

I did find a reference to the exception code here, http://fisheye5.atlassian.com/browse/glassfish/appserv-webtier/src/java/org/apache/catalina/startup/TldConfig.java but I'm still none the wiser.

It might just be a network problem as I'm getting a Connection Refused message in the stack trace.

Anyone have any ideas?

Best wishes,
ngu

SEVERE: PWC1315: Error reading listeners from TLD
javax.servlet.ServletException: PWC3037: Exception processing TLD at resource path /WEB-INF/tld/spring.tld in context /HelloWorld
at org.apache.catalina.startup.TldConfig.tldScanTld(TldConfig.java:750)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:450)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5109)
at com.sun.enterprise.web.WebModule.start(WebModule.java:339)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:973)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:957)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:688)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:3020)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2646)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:72)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:63)
at com.sun.enterprise.v3.server.ApplicationLifecycle.startModules(ApplicationLifecycle.java:609)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:257)
at org.glassfish.embed.GlassFish.deploy(GlassFish.java:422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:946)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:766)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:754)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
at RunAppGf_groovy$_run_closure4.doCall(RunAppGf_groovy:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

...

Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:516)
at java.net.Socket.connect(Socket.java:466)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)

Posted by NewGrailsUser on August 05, 2008 at 12:47 AM PDT #

Just in case anybody saw this problem I was hitting. I found out what was happening.

Looks like the problem I was hitting was to do with our firewall. I've set up the grails proxy via grails set-proxy and everything is working as expected.

Thanks again for the great post. Keep up the good work.

ngu.

Posted by NewGrailsUser on August 14, 2008 at 11:56 PM PDT #

Hi all,

I encountered a HTTP Status 503 error when I tried to deploy my Grails app on Glassfish.

Can somebody help?

Posted by Andrei on October 13, 2008 at 10:22 PM PDT #

Andrei,

Can you give more details about your configuration ? Did you try deploying the app described above or something else ?

Posted by Arun Gupta on October 14, 2008 at 07:16 AM PDT #

My bad.. I know why I got the 503 error message.

The app took a while to startup. However, does it really take about 7-10 minutes to get the application to start up or it would depend on the server environment?

Posted by Andrei on October 14, 2008 at 09:54 AM PDT #

Andrei,

7-10 minutes is certainly way too much by any standards. Can you file a bug at:

https://glassfish.dev.java.net/issues/enter_bug.cgi?issue_type=DEFECT

Choose "deployment" as sub-component.

Posted by Arun Gupta on October 15, 2008 at 07:32 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today