Last updated by
1 year ago
Page: Deployment, Version:40
Deployment
Grails should never be deployed using thegrails run-app command as this sets Grails up in "development" mode which has additional overheads. To deploy a Grails application type:
grails war
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
| Container | Grails 1.0 |
|---|---|
| #Tomcat 5.5 | Y |
| #Tomcat 6.0 | Y |
| #JOnAS 5.1 | Y |
| #JOnAS 5.2 and onwards | Y |
| Geronimo 2.0.2 | Unknown, but see WAS CE below |
| #Geronimo 2.1.1 | Y |
| #GlassFish v1 (Sun AS 9.0) and v2 (Sun AS 9.1) | Y |
| #GlassFish v3 Prelude v3 "Prelude" | Y |
| #IBM Integrated Web Application Server for i 7.1 | Y |
| #Sun App Server 8.2 | Y |
| Websphere 6.1 | Y |
| #Websphere Application Server Community Edition 2.0 (WAS CE) | Y |
| Resin 3.2 | Y |
| Oracle AS | Y |
| #JBoss 4.2 | Y |
| #JBoss 5 | Y |
| #JBoss 6 | Y |
| Jetty 6.1 | Y |
| SpringSource Application Platform 1.0 beta | Y |
| Weblogic 8.1.2 | N |
| Weblogic 9.2 | Y |
| Weblogic 10 | Y |
| #Weblogic 11g | Y |
Deployment Notes
Tomcat
Tomcat deployment is trivial and requires copying the WAR file into the TOMCAT_HOME/webapps folder and restarting the container.Be aware that on default settings, Grails will attempt to write to the tomcat directory certain files, typically the stacktrace.log and the h2 database. Your Tomcat directory is likely installed with owner/group of root, while the Tomcat server runs as user tomcat6. This will cause your application to fail to start with write permission errors. Either change your Grails production settings so that these files are written elsewhere to directories with correct permissions OR change the owner of the Tomcat directory (for Unix: /var/lib/tomcat6) to tomcat6 (or whatever tomcat user you set up using the TOMCAT6_USER setting).JOnAS 5.1
Deploying Grails applications on OW2 JOnAS has been tested on versions 5.1.x (OSGi).- Open the JONAS_BASE/conf/classloader-default-filtering.xml file and make it have the following contents:
<class-loader-filtering xmlns="http://org.ow2.jonas.lib.loader.mapping"> <default-filters> <filter-name>org.apache.commons.digester.*</filter-name> <filter-name>org.springframework.*</filter-name> </default-filters> </class-loader-filtering>
- When you use the g:remoteFunction, g:submitToRemote or other similar methods, you might have the problem that your params seem to all require a URL decoding/escaping. That happens because the Tomcat server embedded into JOnAS uses the ISO-8859-1 character set when decoding the URIs, whereas Grails submits them as UTF-8. To fix this, open the JONAS_BASE/conf/tomcat6-server.xml and JONAS_BASE/conf/tomcat7-server.xml in order to change all the:
<Connector ...
<Connector URIEncoding="UTF-8" ...JOnAS 5.2 and onwards
Deploying Grails applications on OW2 JOnAS has been tested on versions 5.2.x and the latest 5.3.x milestones (OSGi).- When you use the g:remoteFunction, g:submitToRemote or other similar methods, you might have the problem that your params seem to all require a URL decoding/escaping. That happens because the Tomcat server embedded into JOnAS uses the ISO-8859-1 character set when decoding the URIs, whereas Grails submits them as UTF-8. To fix this, open the JONAS_BASE/conf/tomcat6-server.xml and JONAS_BASE/conf/tomcat7-server.xml in order to change all the:
<Connector ...
<Connector URIEncoding="UTF-8" ...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>
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
- Invoke asadmin command as: asadmin deploy myapp-0.1.war
Access your application at http://localhost:8080/myapp-0.1To undeploy invoke : asadmin undeploy myapp-0.1
GlassFish v3 Prelude
With GlassFish v3 Prelude, the user can:- get the Grails distribution right from the Update Center (command-line, update tool, or web admin)
- use GlassFish Embedded when running % grails run-app
- use the % grails war --nojars command to create lightweight archives without the Grails jars (since they are already installed in GlassFish)
IBM Integrated Web Application Server for i 7.1
You can deploy a grails app out of the box.To increase maximum memory size, edit the /www/appserver/lwi/conf/overrides/i5javaopts.javaopt file and add a -Xmx1024m (or more) line.The jndi DataSource name is jdbc/ProxyDS. GORM can probably only access the *DEFAULT connection ID.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.jpgGoes to:http://localhost:8080/amazon-0.1/images/grails_logo.jpg/index.gspThere 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=135If you dograils install-templates
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/
The <g:render> tag causes a java.lang.StackOverflowError when deploying a Grails app version 1.1.1 or later on WebSphere 6.1.
Grails app version 1.1 works fine on WAS 6.1 but something happened with Grails 1.1.1 and beyond that breaks the render tag.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...
- Delete commons-logging-1.1.jar from the lib directory
- Add commons-logging-adapters-1.1.jar to the lib directory
- After adding the application, modify the classloader to "Parent last."
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
- Check that you have patched WebSphere with the latest fixpack (6.1.0.11 or later)
- Set the the property 'com.ibm.ws.webcontainer.invokefilterscompatibility' to 'true' (Servers -> Application Servers -> <server> -> Web Container Settings -> Web Container -> Custom Properties)
- Restart WAS, the 500 should only happen now on the first page, if you append index.gsp to the URL it should work
- 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>
- Install the templates with the command :
grails install-templates
- 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>
- Repackage and redeploy your application
AS/400, i5/OS, IBM i Websphere
By default, on OS/400, Websphere application server uses the classic JVM. Since version 1.0, grails doesn't work with class JVM, you have to switch your websphere instance to the IBM technology for java VM, with qshell, run the following command: /QIBM/ProdData/Websphere/AppServer/V61/edition/bin/enableJvm -jvm std32 -profile profileWebsphere 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!- 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>
- Build .war file
- Start WAS CE and login into management console
- Go to Applications->Deploy new
- As 'Archive' choose your .war file
- 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.1JBoss 5
Take a look at this article on deploying a Grails application to JBoss 5.- Remove logging libs from grails app because they're already supplied by Jboss - BuildConfig.groovy
// removing logging libs
grails.war.resources = {stagingDir ->
def toRemove = [
"$stagingDir/WEB-INF/lib/log4j-1.2.14.jar", // log4j supplied by JBoss
"$stagingDir/WEB-INF/lib/log4j-1.2.15.jar", // log4j supplied by JBoss
"$stagingDir/WEB-INF/lib/log4j-1.2.16.jar", // log4j supplied by JBoss
"$stagingDir/WEB-INF/classes/log4j.properties", // logging conf done in JBoss only
"$stagingDir/WEB-INF/lib/slf4j-api-1.5.6.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/slf4j-api-1.5.8.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/slf4j-api-1.6.2.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/slf4j-log4j12-1.5.6.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/slf4j-log4j12-1.5.8.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/slf4j-log4j12-1.6.2.jar", // slf4j supplied by JBoss 5+
"$stagingDir/WEB-INF/lib/jcl-over-slf4j-1.5.6.jar", // jcl supplied by JBoss as well
"$stagingDir/WEB-INF/lib/jcl-over-slf4j-1.5.8.jar", // jcl supplied by JBoss as well
"$stagingDir/WEB-INF/lib/jcl-over-slf4j-1.6.2.jar", // jcl supplied by JBoss as well
].each {
delete(file: it)
println("removing ${it}")
}
}- Remove log4j configuration from grails app web.xml, in profit to JBoss config - scripts/_Events.groovy
// conf processing restricted to war command
// otherwise run-app command fails.
eventCreateWarStart = { warName, stagingDir ->
def webXmlFile = new File("${stagingDir}/WEB-INF/web.xml")
def root = new XmlSlurper().parse(webXmlFile) // When running with JBoss (or GlassFish a.s.o) remove log4j configuration stuff
def log4j = root.listener.findAll {node ->
node.'listener-class'.text() == 'org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener'
}
log4j.replaceNode {}
def log4jFile = root.'context-param'.findAll {node ->
node.'param-name'.text() == 'log4jConfigLocation'
}
log4jFile.replaceNode {}
def writer = new FileWriter(webXmlFile)
writer << new StreamingMarkupBuilder().bind {
mkp.declareNamespace("": "http://java.sun.com/xml/ns/j2ee")
mkp.yield(root)
}
writer.close()
}- Deactivate some code loading in grails-app embedded hibernate -
Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager) at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getDeclaredConstructor(Class.java:1985) at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1669)
hibernate { validator.apply_to_ddl = false
validator.autoregister_listeners = false
}JBoss 6
If you have trouble deploying to JBoss 6 with the error "Error visiting resource: VFSResourceContext" you can skip scanning of that jar with a jboss-scanning.xml descriptor in the WEB-INF folder, e.g.<?xml version='1.0' encoding='UTF-8' ?>
<scanning xmlns='urn:jboss:scanning:1.0'>
<path name='WEB-INF/lib/grails-datastore-gorm-*.jar'>
<include name='org.grails.datastore' />
</path>
</scanning><?xml version="1.0" encoding="UTF-8" ?> <classloading xmlns="urn:jboss:classloading:1.0" domain="your_war_name.war" export-all="NON_EMPTY" import-all="true" />
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.htmlNote if you use a JNDI dataSource you need to allow parent classes to load firstWeblogic 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.htmlWeblogic 9.2
Default Grails 1.1 applications fail to deploy on Weblogic 9.2 with the following exception:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.tools.ant. helper.AntXMLContext.setCurrentTargets(Ljava/utilMap;)
<?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd"> <container-descriptor> <prefer-web-inf-classes>true</prefer-web-inf-classes> </container-descriptor> </weblogic-web-app>
Weblogic 11g
I have found three problems deploying my app to Weblogic.You must make a WEB-INF/weblogic.xml file with the following minimum content:<?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"> <wls:weblogic-version>10.3.2</wls:weblogic-version> <wls:context-root>wsc2</wls:context-root> <wls:container-descriptor> <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> </wls:container-descriptor> <wls:session-descriptor> <wls:cookie-name>WSC2SESSIONID</wls:cookie-name> </wls:session-descriptor> </wls:weblogic-web-app>
The server does not like -0.1 context root
To select an apropiate name for your app in the weblogic server write in weblogic.xml:....
<wls:context-root>wsc2</wls:context-root>
....The server cannot find the WEB-INF/lib classes
I noticed this error thanks to this exception: ClassNotFoundException: org.hibernate.hql.ast.HqlToken This error happens with all the packages contained by default in the Weblogic classpath like antlr.jar or hibernate-core.jar. This solution makes Weblogic prefer to look for classes in the WEB-INF/lib jars folder.Solution:.... <wls:container-descriptor> <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> </wls:container-descriptor> ....
The server lost the session redirecting between servlets
This happens when you login in the controller and validates user in .gsp file. For example.Avoid this error naming the session cookie:.... <wls:session-descriptor> <wls:cookie-name>WSC2SESSIONID</wls:cookie-name> </wls:session-descriptor> ....