0

I have setup an environment variable like this:

APP_HOME = "c:\app\app-datasource.properties

in config.groovy I do

def ENV_NAME = "APP_HOME"
    if(!grails.config.location || !(grails.config.location instanceof List)) {
    grails.config.location = []
    }
    if(System.getenv(ENV_NAME)) {
    println "Including configuration file specified in environment: " + System.getenv(ENV_NAME);
    grails.config.location << "file:" + System.getenv(ENV_NAME)

    } else if(System.getProperty(ENV_NAME)) {
    println "Including configuration file specified on command line: " + System.getProperty(ENV_NAME);
    grails.config.location << "file:" + System.getProperty(ENV_NAME)

    } else {
    println "No external configuration file defined."
    }

I got this from a post online, I want to know if we need to use grails.config.location or grails.config.locations ? Also instead of APP_HOME being set to the properties file directly, can I set it to a directory path (e.g.: c:\apps) and then can I have multiple properties files placed in that directory, then if I do the following multiple times will it work?:

    grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-datasource.properties"
    grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-reporting.properties"
and so on...

Thanks in advance

pri_dev
  • 11,315
  • 15
  • 70
  • 122

1 Answers1

1

You need to modify grails.config.locations (plural). My (very limited) experience says that the external files are probably not loaded until after Config.groovy is completed.

You might want to consider looking for he additional configuration file on your classpath; then you can put your extra outside of the Grails project (e.g., in your web server's library) or within the grails-app/conf directory. I have written the instructions on how to do that here.

Here's a post on how to do it from a plugin: https://stackoverflow.com/a/9789506/1269312

Community
  • 1
  • 1
Big Ed
  • 1,056
  • 9
  • 20
  • Thanks for the tip Ed, I am going to try this, One other thing is grails has a predefined setup to read from ../${appName}-config.properties for properties related to datasource.groovy (Like I am using a codec for password so I use codec.decode("encrypted passwd") in datasource, how do I do this in properties file?), and even the labels are defined by grails like dataSource.username, dataSource.driverClassName etc. How do I customize or add some more properties which are read at run-app and used in dataSource.groovy? – pri_dev Mar 26 '12 at 16:56
  • If you look at the top of the original `Config.grooy` file, you will see that it has some suggestions in the comments about how to do that. You might have to code your file into `scripts/Events.groovy` as I did in the posts I linked to. I don't know the answer to the dataSource.groovy question; I just replace the default `DataSource.groovy` with my own. I think that you would want to use a JNDI DataSource when you deploy the application, which would not require you to store a password in the war file. – Big Ed Mar 26 '12 at 17:12