22 Deployment - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.1
22 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 any 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 rungrails package
:$ grails package
java -Dgrails.env=prod -jar build/libs/mywar-0.1.jar// orjava -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 thebuild/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
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"