Sunday, November 28, 2010

How to Deploy a grails 1.3.5 webapp to JBoss 5.1.0.GA

There are a few problems that prevent grails deploying to the JBoss application server. I will describe specifically how to deploy a grails 1.3.5 web application to the JBoss 5.1.0.GA Applicaton Server community edition.

A bug has been filed on the grails Jira server describing the problem. Please create a Jira account and vote for this issue so that it may get more attention. The issue is Grails-6953.


The first issue is that newer versions of hibernate require hibernate validator even though grails doesn't need it. This is Jira issue Grails-5606 and says that it was fixed in grails 1.2.2 but wasn't.

In the text of Grails-5606 there was a work around described by Graeme Rocher that solves the issue. The work around is:

In BuildConfig.groovy:
  1. Uncomment the JBoss maven repository
  2. Add the hibernate-validator dependency
runtime('org.hibernate:hibernate-validator:3.1.0.GA') {
excludes 'slf4j-api', 'hibernate.core', 'hibernate-comnmons-annotations', 'hibernate-entitymanager'
}


The second issue is that grails includes logging libraries that JBoss already includes. JBoss complains about this. There is a good post covering that issue here. The logging libraries can be removed from the grails war file by adding the following to the end of the BuildConfig.groovy file:

// Remove logging artifacts from war
grails.war.resources = { stagingDir ->
def toRemove = [
"$stagingDir/WEB-INF/lib/log4j-1.2.16.jar",
"$stagingDir/WEB-INF/lib/commons-logging.jar",
"$stagingDir/WEB-INF/lib/commons-logging-1.1.jar",
"$stagingDir/WEB-INF/lib/jcl-over-slf4j-1.5.8.jar",
"$stagingDir/WEB-INF/lib/slf4j-api-1.5.8.jar",
"$stagingDir/WEB-INF/lib/slf4j-log4j12-1.5.8.jar"
].each {
delete(file: it)
}
}


The third issue has to do with how grails creates the filename of the war. Grails constructs the war filename based on properties defined in application.properties. The war filename is app.name-app.version.war. When deploying the grails web application to an environment for testing, we may not want to access the application like:

http://mysite.com/myapp-0.1/

To get around this issue, we can create a jboss-web.xml file in the web-app/WEB-INF folder. The contents of the jboss-web.xml file are:

<jboss-web>
<context-root>/wis</context-root>
</jboss-web>