Archive for July 9th, 2011

New grails-standalone plugin

Saturday, July 09th, 2011

I noticed a while back looking at open Grails issues that there was an interesting one about running a Grails application as a standalone jar, GRAILS-99. Jenkins has this option and uses Winstone but I wasn’t able to get it completely working with a Grails application. It would start up and serve the index GSP but controller-based actions just showed a blank page. It might have been fixable, but the project hasn’t been updated since 2008 and I didn’t want to invest a lot of time on this so I did it a bit more manually using Tomcat.

I took the same approach as Winstone, i.e. creating a JAR with a Main-class entry in the manifest for a class that extracts an embedded WAR file to a temporary folder and uses a servlet container to host the application. I’m using Tomcat 7.0.16 and borrowed a lot of code from the Tomcat plugin. There’s a Gant script (build-standalone) which builds a WAR (or uses an existing one if specified) and builds the JAR by expanding the five Tomcat jars and adding the WAR and the launcher class.

There are a few configuration options, but the simplest workflow is to run

grails build-standalone

in your project directory, which creates target/standalone.jar, and then run

java -jar standalone.jar

and the application will be running at http://localhost:8080.

The plugin portal page is here, the full docs are here and the source is here. Report issues and suggestions on the User mailing list.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.