3

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?

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
  • Have you tried: grails.config.locations = ["file:${System.env.CATALINA_HOME}/conf/myconfig.properties"] – mwaisgold Jun 04 '14 at 13:50

1 Answers1

4

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.