(Quick Reference)

21 Deployment - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari

Version: 3.0.0.RC3

21 Deployment

Grails applications can be deployed in a number of ways, each of which has its pros and cons.

"grails run-app"

You should be very familiar with this approach by now, since it is the most common method of running an application during the development phase. An embedded Tomcat server is launched that loads the web application from the development sources, thus allowing it to pick up an changes to application files.

You can also deploy to production this way using:

grails prod run-app

"Runnable WAR or JAR file"

Another alternative in Grails 3.0 or above is to use the new support for runnable JAR or WAR files. To create runnable archives run grails package:

$ grails package

You can then run either the WAR file or the JAR using your Java installation:

java -Dgrails.env=prod -jar build/libs/mywar-0.1.jar

// or

java -Dgrails.env=prod -jar build/libs/mywar-0.1.war

A TAR/ZIP distribution

The package will also produce a TAR and a ZIP file in the build/distributions directory. If you extract these archives (typically the TAR on Unix systems and the ZIP on Windows) you can then run bash file which is the name of your application located in the bin directory.

For example:

$ grails create-app helloworld
$ cd helloworld
$ grails package
$ tar -xvf build/distributions/helloworld-0.1.tar
$ export HELLOWORLD_OPTS=-Dgrails.env=prod
$ helloworld-0.1/bin/helloworld
Grails application running at http://localhost:8080

WAR file

A common approach to Grails application deployment in production is to deploy to an existing Servlet container via a WAR file. Creating a WAR file is as simple as executing the war command:

grails war

This will produce a WAR file that can be deployed to a container in the build/libs directory.

Note that by default Grails will include an embeddable version of Tomcat inside the WAR file so that it is runnable (see the previous section), this can cause problems if you deploy to a different version of Tomcat. If you don't intend to use the embedded container then you should change the scope of the Tomcat dependencies to provided prior to deploying to your production container in build.gradle:

provided "org.springframework.boot:spring-boot-starter-tomcat"

Application servers

Ideally you should be able to simply drop a WAR file created by Grails into any application server and it should work straight away. However, things are rarely ever this simple. The Grails website contains a list of application servers that Grails has been tested with, along with any additional steps required to get a Grails WAR file working.