Tom Comer
Tom Comer

Reputation: 11

Grails 3.0 context path when deploying to external Tomcat Server

I would like to deploy my Grails 3.0 application to an external Tomcat Server instance and not use the embedded tomcat 8 server. The issue I am running into is that there seems to be no way to set the context path when deploying the WAR file to an existing Tomcat 8 container.

In the grails 2.x line, the META-INF/MANIFEST.MF file that was generated contained the Webapp-Context attribute that contained the context path the app could be reached on. With grails 3.0 and deploying the WAR file, the context path is just the name of the war file (without the .war).

Setting server.contextPath in either the application.groovy or application.yml config files has no effect (these only seem to be used when using the embedded tomcat server).

How can I set the context path on Tomcat 8 for a Grails 3.0 war file?

Upvotes: 1

Views: 1156

Answers (1)

Tom Comer
Tom Comer

Reputation: 11

I figured out a workaround. By default, grails 3.0 creates a war file of the form <app name>-<app version>.war, which causes the default context path to be <app name>-<app version>.

The fix I used was to edit the build.gradle file to customize the name of the war file. Using the documentation for Tomcat 8, I was able to change the war.archiveName property to

archiveName = "${project.name}##${project.version}.war"

This makes Tomcat 8 take the part before the ## as the context path and the part after the ## as the version. This works around the issue I was having.

Upvotes: 0

Related Questions