Last updated by 5 years ago

Page: Deployment, Version:8

Deployment

Grails should never be deployed using the {{grails run-app}} command as this sets Grails up in "development" mode which has additional overheads. To deploy a Grails application type:

grails war
This will create a Web Application Archive (WAR) file from the app name and version found in the application.properties file. For example myapp-0.1.war

Now take this WAR file and install it into your container of choice. See below for container specific installation.

If memory is not a problem on your server then allocate a large amount of memory, such as 512M or more. Also use the server VM option. EG: (-server -Xms512M -Xmx512M). Usually it is better to set both min and max heap size to the same in server applications.

However, if you running on a virtual host with limited memory, Grails 1.0 RC1 has been tested on tomcat 6 with both -Xmx96M and -Xmx128M, it performed well with both settings. I've heard reports of it running on lesser configurations. See: Grails Test On Virtual Server for more information.

Container Support Matrix

ContainerGrails 1.0
#Tomcat 5.5Y
#Tomcat 6.0Y
Geronimo 2.0.2Unknown, but see WAS CE below
#Geronimo 2.1.1Y
#GlassFish v1 (Sun AS 9.0)Y
#GlassFish v2 (Sun AS 9.1)Y
#GlassFish v3Y
#Sun App Server 8.2Y
Websphere 6.1Y
#Websphere Application Server Community Edition 2.0 (WAS CE)Y
Resin 3.2Y
Oracle ASY
JBoss 4.2Y
Jetty 6.1Y
SpringSource Application Platform 1.0 betaY
Weblogic 8.1.2N

Deployment Notes

Tomcat

Tomcat deployment is trivial and requires copying the WAR file into the TOMCAT_HOME/webapps folder and restarting the container.

Geronimo 2.1.1

To deploy a Grails application into Geronimo 2.1.1 (which is bundled with either Tomcat or Jetty) you will have to make a Geronimo plan (${PROJECT_HOME}/web-app/WEB-INF/geronimo-web.xml) which specifies an inverse class loader strategy:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
 xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
 xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
 xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>group_id</sys:groupId>
      <sys:artifactId>artifact_id</sys:artifactId>
      <sys:version>1.0</sys:version>
      <sys:type>war</sys:type>
    </sys:moduleId>
    <!-- For Grails to work properly we use the "parent-last" strategy : -->
    <inverse-classloading/>
  </sys:environment>
  <context-root>/YourApplication</context-root>
</web-app>

This is adequate for deploying to a Jetty based Geronimo application server. However, for deploying to a Tomcat based Geronimo application server, you must also delete jta.jar from the WAR file generated by Grails. That's it - you can now drop the WAR into ${GERONIMO_HOME}/deploy

GlassFish

To deploy a Grails application into GlassFish v1 ( Sun Java System Application Server 9.0), Glassfish v2 ( Sun Java System Application Server 9.1 Update 1 and 2 ) and GlassFish v3
  • Take the WAR file and drop it in the autodeploy directory of the domain onto which you wish to deploy. For example $GLASSFISH_HOME/domains/domain1/autodeploy
Or
  • Invoke asadmin command as: asadmin deploy myapp-0.1.war

Access your application at http://localhost:8080/myapp-0.1

To undeploy invoke&nbsp; asadmin undeploy myapp-0.1

For latest on Groovy/Grails support in GlassFish, visit Groovy and Grails in GlassFish Wiki .

Sun App Server 8.2

Follow the same instructions as deployment onto GlassFish above. However, Sun App Server 8.2 has a bug relating to <welcome-file-list> definitions. Essentially it routes all requests for static resources like images to the GSP servlet so a URL like:

http://localhost:8080/amazon-0.1/images/grails_logo.jpg

Goes to:

http://localhost:8080/amazon-0.1/images/grails_logo.jpg/index.gsp

There seem to be known problems with this version of Sun App Server and a welcome file list definition.

http://forum.java.sun.com/thread.jspa?threadID=5135956&tstart=135

If you do

grails install-templates
And them remove the <welcome-file-list> definition from the src/templates/war/web.xml file

And then WAR it up and deploy Grails works fine (except for index.gsp)

You could get around the lack of an index.gsp you can replace it with a JSP or HTML redirect to a controller

Websphere 6.1

  • Access the WebSphere integrated console typically at a location like: http://localhost:9060/ibm/console
  • Select Applications/Install New Application
  • Browse for the WAR file and then enter a context path that matches the name of the WAR. For example if you have a myapp-0.1.war then enter /myapp-0.1 as the context path
  • Keep clicking "Next" and then click "Finish" to complete
  • Go back to Applications/Enterprise Applications select the checkbox next to the app you just installed and click the "Start" button
  • You should now be able to access the application via the port you installed WebSphere's HTTP listener on. For example: http://localhost:9080/myapp-0.1/

I get a org.apache.commons.logging.LogConfigurationException what happened?

When trying to load a WAR file on WAS 6 and selecting "Parent last" as the classloader option, some users report the following error:

Caused by: org.apache.commons.logging.LogConfigurationException: The chosen 
LogFactory implementation does not extend LogFactory. 
Please check your configuration...
The following steps are reported to work in solving this problem:
  1. Delete commons-logging-1.1.jar from the lib directory
  2. Add commons-logging-adapters-1.1.jar to the lib directory
  3. After adding the application, modify the classloader to "Parent last."
For more information, IBM offers a 20-page PDF document on how to get commons-logging to work with WebSphere. (See also GRAILS-515.)

I get an error like 'java.lang.NoSuchMethodError: org.apache.tools.ant.UnknownElement: method setNamespace(Ljava/lang/String;)V not found' what do I do?

WebSphere ships with an old version of ant.jar in $WASHOME/lib You will see errors like 'java.lang.NoSuchMethodError: org.apache.tools.ant.UnknownElement: method setNamespace(Ljava/lang/String;)V not found'. Workaround: replace the ant.jar with a more recent version of ant (e.g. from GRAILS_HOME/lib).

I'm getting a 500 error code when I try to access my application

  1. Check that you have patched WebSphere with the latest fixpack (6.1.0.11 or later)
  2. Set the the property 'com.ibm.ws.webcontainer.invokefilterscompatibility' to 'true' (Servers -> Application Servers -> <server> -> Web Container Settings -> Web Container -> Custom Properties)
  3. Restart WAS, the 500 should only happen now on the first page, if you append index.gsp to the URL it should work
  4. Create a file index.html under the webapp directory with the following content :
<html>
  <head>
    <meta HTTP-EQUIV="REFRESH" content="0; url=index.gsp">
  </head>
  <body/>
</html>
  1. Install the templates with the command :
grails install-templates
  1. Modify the <welcome-file-list> section of the file src/templates/war/web.xml with :
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
  1. Repackage and redeploy your application

Websphere Application Server Community Edition 2.0

WAS CE is much like Apache Geronimo. Possible errors during deployment might be connected to java version (try Sun's java 1.5) and/or conflicting libraries.

For informations about deployment plan for Geronimo, see: http://cwiki.apache.org/GMOxDOC11/geronimo-webxml.html.

For additional informations about changing loading policy see: http://www-1.ibm.com/support/docview.wss?uid=swg21261287.

Note that deployment at WAS CE was not heavily tested so far!

  1. Create web-app/WEB-INF/geronimo-web.xml similiar to one below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
 xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
 xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
 xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>group_id</sys:groupId>
      <sys:artifactId>artifact_id</sys:artifactId>
      <sys:version>1.0</sys:version>
      <sys:type>war</sys:type>
    </sys:moduleId>
    <hidden-classes>
      <filter>org.springframework</filter>
      <filter>org.apache.cxf</filter>
      <filter>org.apache.commons</filter>       
      <filter>org.jaxen</filter>
    </hidden-classes>
  </sys:environment>
  <context-root>/YourApplication</context-root>
</web-app>
  1. Build .war file
Execute 'grails war' at your project's folder
  1. Start WAS CE and login into management console
  2. Go to Applications->Deploy new
  3. As 'Archive' choose your .war file
  4. Click install

JBoss 4.2

Deploying onto JBoss 4.2 is trivial, simply start-up JBoss then drop the WAR file into the JBOSS_HOME/server/default/deploy directory (or the relevant profile you want to deploy to). JBoss will automatically deploy the Grails application which will then be accessible via something like: http://localhost:8080/myapp-0.1

Resin (3.1.3)

Deploying Grails onto Resin running with Apache as frontend may cause Apache not to pass request handling to Resin for grails-like URLs such as "/controller/action/1". Apache (and mod_caucho) considers this to be a normal physical directory access because there are no servlet mapping in the web.xml for such URLs. To fix this problem, simply add "SetHandler caucho-request" to your .htaccess file inside your webapp's document root directory. This will pass all URLs to caucho for processing. This can also be done using <Location> or <LocationMatch> in your apache configuration.

Oracle AS

There is a great article about how to deploy onto Oracle AS here: http://www.oracle.com/technology/pub/articles/grall-grails.html

Weblogic 8.1.2

The most important thing to remember is that this version only supports servlet spec 2.3 so you need to make sure that the web.xml uses a DTD and not the 2.4 schema. WL also doesn't adhere strictly to the servlet spec and doesn't load listeners before servlets which can cause problems where the dispatcher cannot run because the application context hasn't been loaded. Have a look at this link for more info http://www.jdocs.com/spring/1.2.8/org/springframework/web/context/ContextLoaderServlet.html