I have struggled a lot with getting our corporate-standard WebSphere container to play nicely with Grails in the past and when we moved to Grails 2.1.1 and WebSphere 7.0 it was no different.
EAR Script
The first thing you will want to do is add the Ear script to your project under scripts.
includeTargets<<grailsScript("_GrailsWar")target(ear:"Creates an EAR file from a Grails WAR"){war()event("StatusUpdate",["Building EAR file"])generateApplicationXml()defwarDest=newFile(warName).parentFiledefappVersion=metadata.getApplicationVersion()defearFile="${projectTargetDir}/${contextRoot}-${appVersion}.ear"ant.ear(destfile:earFile,appxml:appXml,update:true){fileset(dir:warDest,includes:"*.war")}event("StatusFinal",["Done creating EAR $earFile"])}target(defineContextRoot:"defines the context root"){contextRoot="${grailsAppName}"}target(generateApplicationXml:"Generates an application.xml file"){depends(defineContextRoot)defwarDest=newFile(warName)appXml="${projectTargetDir}/application.xml"newFile(appXml).write"""<?xml version="1.0" encoding="UTF-8"?><application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"><display-name>${grailsAppName}</display-name><module> <web> <web-uri>${warDest.name}</web-uri><context-root>${contextRoot}</context-root> </web></module></application>"""}setDefaultTarget(ear)
Install Web.xml and JNDI
If, like us, you use JNDI for your database connection you will probably want to add it to the web.xml. Just run the grails install-templates command and modify your web.xml with your jndi node similar to below.
If you need this jndi available in dev (run-app local mode) you will need to add it to your Config.groovy.
12345678910111213141516171819
environments{development{// this will create the JNDI entry in the tomcat plugin for local executiongrails.naming.entries=["jdbc/MyName":[type:"javax.sql.DataSource",//requiredauth:"Container",// optionaldescription:"Data source for Database",//optionaldriverClassName:"com.mysql.jdbc.Driver",url:"jdbc:mysql://server:3306/db?useOldAliasMetadataBehavior=true",username:"blah",password:"secret",maxActive:"8",maxIdle:"8",poolPreparedStatements:"true"]]}}
Additional WebSphere Web Xml Settings
There are two additional files you will probably need to create and put into your web-app\WEB_INF directory.
In “Application servers > server > Process Definition > Java Virtual Machine” set “Generic JVM arguments” to “-Xverify:none”
In “Application servers > server > Process Definition > Java Virtual Machine > Custom Properties”, add a custom property name: com.ibm.ws.classloader.getInputStream.enableIOException value: true
In “Application servers > server > Web container > Custom Properties”, add a custom property name: com.ibm.ws.webcontainer.invokeFiltersCompatibility value: true
Also you will need to make sure that your Enterprise Application > Class loading and update detection
Classes loaded with local class loader first (parent last)
Single class loader for application
War Settings
In the end you will probably have jar/lib hell and your application may not start correctly. Make sure all your plugins and dependencies have appropriate excludes. For example, we are using spring security (not the plugin) and here is one dependency exclude example: