TheKojuEffect
TheKojuEffect

Reputation: 21081

Externalize grails application configuration to tomcat conf directory

I'm trying to externalize configuration for a grails application.

I've successfully externalized such that configuration file is in user home directory as follows.

grails.config.locations = ["file:${userHome}/.conf/${appName}-config.properties"]

However, I need to externalize such that configuration file need to be inside tomcat/conf directory.

In other non-grails applications, I used to achieve this by specifying config location to be at ${CATALINA_HOME}/conf.

How can configurations be externalized to a tomcat/conf directory in grails?

Upvotes: 3

Views: 1845

Answers (1)

Jean-Louis Jouannic
Jean-Louis Jouannic

Reputation: 148

When running an application in Tomcat, catalina.home and catalina.base are available in Java system properties.

So you can use them in your Config.groovy file to add a new path to grails.config.locations:

grails.config.locations = []
def tomcatConfDir = new File("${System.properties['catalina.home']}/conf")
    if (tomcatConfDir.isDirectory()) {
    grails.config.locations << "file:${tomcatConfDir.canonicalPath}/${appName}-config.groovy"
}

This is just an example, but it works.

Upvotes: 4

Related Questions