Posts Tagged ‘Externalized’

Externalize datasource configuration in Grails

March 11, 2010

the following seems to work to externalize datasource configuartion (see http://jira.codehaus.org/browse/GRAILS-3226?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel)
Basically
1) you add the grails.config.locations property in the Config.groovy like below

grails.config.locations = [ //”classpath:${appName}-config.properties”,
//”classpath:${appName}-config.groovy”,
“file:${userHome}/${appName}-config.properties”]

Notice: I have added the file is users file system , so the user can change it, without touching the war file . Restarting the app should pick up the new value
2) in the ${appName}-config.properties” file

dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://localhost/something
dataSource.username=root
dataSource.password=secret

Notice no quotes in the value
I am using grails 1.2.1

Grials Externalizing properties

March 11, 2010

I wanted to add a properties files to the existing war file before app is deployed through a script.
Several steps
1) open the {appName}/grails-app/conf/Config.groovy
2) change “grails.config.locations” property in the file to

grails.config.locations = [“file:./grails-app/conf/${appName}-config.properties”]

3) create the {appName}-config.properties in

{appName}/grails-app/conf/

Possible problem: In war file, the properties file ends up in

WEB-INF\classes\

directory, so It might be better to just uncomment the
grails.config.locations existing already in step 2
Need to test.

Also see this site .

“The configuration mechanism of Grails is nice, but there is a small trouble. The configuration files are compiled and packed into the deployment package (WAR) during project build phase. However, one usually does not want to rebuild the whole application just to change say a database password. So, how to do it? “

This could be another option — but the problem is given a war file in tomcat how does one access those files
Does the

“file:${userHome}/.grails/${appName}-config.properties”

for the property ” “grails.config.locations” take care of it?
Need to test