Apache Geronimo on Grails (Michael Galpin)
Grails, Michael Galpin July 9th, 2008
DeveloperWorks has published an article by Michael Galpin that demonstrates how to setup a Grails application to be run inside a Geronimo server.
Do you want to build your Web sites faster and cheaper, but still leverage industrial-strength technology? You can do just that using Grails and Apache Geronimo. Grails leverages the power of the dynamic language Groovy to accelerate your development. However, it runs on the Java® Virtual Machine and leverages proven Java technologies. This makes it easy to take your Grails application to the next level by deploying it to Apache Geronimo, the premiere open source Java EE V5-certified application server.
The article is divided in two. The first part describes the sample application, which in out opinion is quite complete, as it setups the application from the beginning, configures both domain classes and controllers, adds a handy service and wires it up to the controller, finally showing off some of GORM’s dynamic finders (it only lacked custom views, but the default ones are enough for this app).
The second part describes how to deploy the application into a Geronimo server. Michael remarks two things you must take into account to achieve this goal.
The first step in deploying our Grails application to Geronimo is to create a WAR. Looking at the Grails directory structure, it would not be too hard to write an Ant script to do this, but luckily, Grails make it even easier by providing a simple Grails command:
war. The script compiles code from the grails-app tree and combines it with code from the base Grails ($GRAILS_HOME ) directory. The result is added to the /web-app directory. Since you are using Geronimo, you need to add a Geronimo deployment plan. You can simply create a geronimo-web.xml file in /web-app/WEB-INF.
Geronimo deployment plan
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"> <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1"> <moduleId> <groupId>grailsApps</groupId> <artifactId>AdServer</artifactId> <version>0.1</version> <type>war</type> </moduleId> <hidden-classes> <filter>org.springframework</filter> <filter>org.apache.cxf</filter> <filter>org.apache.commons</filter> </hidden-classes> </environment> <context-root>/adserver</context-root> </web-app>There is one very important thing to notice here, and that is the hidden-classes section. These are packages that are included by default with Geronimo, but are also included with Grails. This tells the class loader that will load our Grails app, to ignore any classes from these packages available to the parent class loader (i.e., the container’s class loader). This will guarantee that the Grails versions of these classes are loaded and we will not have any nasty class-loader conflicts.
Finally he demonstrates the requires steps to setup a JNDI Datasource, which is actually a connection pool managed by Geronimo.
Tags: Grails, Michael Galpin
About