Altering external configuration file location after a war has been created?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Altering external configuration file location after a war has been created?

welshyoo
I have a requirement to allow users to specify the location of their own external configuration file for a war file to look for.

Looking through the documentation and several sources I haven't seen a way to this. All the examples I have seen have a number of values hardcoded in config.groovy for the application to look for configuration files in.

Is there any method avaiable for changing these locations? I wouldn't expect that their is as these locations are specified before the war is built.

So as far as I can see I have a number of options :
1) Create a new war every time a customer wants the location of their configuration file to change (Definitely not ideal)
2) Hard code a number of location values and have the user put their configuration there. I wonder is this reasonable? Have people on other projects taken this approach?
3) Have a build script that the customer uses when they deploy the war that copies their configuration file to somewhere in the web-app that has its location hard coded (I'm not sure if this would work but I can't see why it wouldn't)

I'd be interested to hear how other people have addressed this issue in the past?
Reply | Threaded
Open this post in threaded view
|

Re: Altering external configuration file location after a war has been created?

jasons
Was thinking about this as well as on a previous project the operations guy complained about the build process and having to have various configs inside the WAR file.

The easiest way I came up with was to require an environment variable that points to a directory.

So on the server you have a MYAPP_HOME environment variable set to /home/myapp or c:\myapp or whatever.

Then you put a config file in there, in my case I have a myapp-datasource.groovy and myapp-config.groovy.

Then what I do to pull those in when the app runs is in the Config.groovy inside the WAR file I have:

grails.config.locations = ["file:" + System.getenv("MYAPP_HOME") + File.separator + "myapp-config.groovy",
                                                   "file:" + System.getenv("MYAPP_HOME") + File.separator + "myapp-datasource.groovy"]

In the DataSource.groovy inside my WAR I don't have any environment specific settings, they're all pulled out to the external file.  Works great!

There's also a way to do this with setting a parameter in the JVM startup, but environment variables seemed easier to work with for most people.  Hope that helps.