Grails 3 and Deployment to Tomcat Container

Datetime:2016-08-23 03:52:39          Topic: Tomcat           Share

April 22, 2016 by Manvendra Singh | 0 comments

Any web application consists mainly of two tasks, i.e, development, and deployment. For development, we can use any tools but for deployment, we need to be careful of what environments are supported by the framework.

At the time of Grails 2, we just needed to execute grails war and put the generated war to a container, most probably Tomcat’s webapps folder, and optionally restarting the container.

Starting with Grails 3, it’s much simpler, due to the embedded, default, Tomcat container, which is specified inside the build.gradle as follows:

dependencies {
    compile "org.springframework.boot:spring-boot-starter-tomcat"
}

We just need to execute grails war  or  ./gradlew bootRepackage and then execute the resulted war using java -jar build/libs/my-app-0.1.war . This would listen by default on port 8080.

See! No more specialized containers!

But wait, what if we need to deploy it to a container? Just putting this resulted war inside Tomcat’s webapps folder won’t work anymore.

Any workaround? Yes, there is.

Just change the scope of Tomcat’s dependency to provided from the compile as shown below:

dependencies {
    provided "org.springframework.boot:spring-boot-starter-tomcat"
}

And then just generate the war and run it any way you want. Easy right?

The bonus is, our development environment is still intact by this change of the dependency scope, we are still running our grails run-app  without any issue.

As a note on the Tomcat version, we need to use Tomcat 7.0.55 , or else it won’t work. I’m currently using Grails 3.1.4 . More information on supported containers can be found at https://grails.org/wiki/Deployment .

For further information on this topic head to http://grails.github.io/grails-doc/3.1.4/guide/deployment.html .

Thanks for reading till here. See you next time.





About List