views:

130

answers:

3

Hi How would you solved that?

I have one application in which I have a few configuration files, I make war file and deploy it on the tomcat.

But at the same time I have to make the war file and deploy the same application under different context and/or a server with modified configuration files.

I can create my own task in ant, and replace needed paramaters but there can be possibility of moving to maven, and anyway I'm not sure about it. Or can I use something like spring's property place holder configurer or jgroups

+1  A: 

Spring can handle this quite well in a variety of ways. The approach I found most useful and flexible is to setup in each environment a system variable that specifies trhe environment name e.g. test, dev, int, prod, etc.

Spring can then use this system variable to load the correct property files. Depending on your needs these property files can be bundled with the app or loaded from an external location. Theres an example of a similar approach here:

http://www.developer.com/java/ent/print.php/3811931

Pablojim
and is it possible to use it for making war file with a little bit modified configuration files file? eg. for one war file in something.properties property address=one and for second war file in the same file something.properties address=second ? thx
blefesd
@blefesd - in short no. However I advise not to take this approach. It's best to have only one version of deployables and either have all the configuration included in it or loaded from external locations. Some reasons for this are ease of versioning, ability to add new environments and traceablity.
Pablojim
A: 

I'd deploy Spring apps packaged as a WAR to either Tomcat or WebLogic without any changes. It would contain both the META-INF/context.xml for Tomcat and weblogic.xml for WebLogic. No worries, no changes.

duffymo
A: 

What we did was create a folder structure for the properties that were environment specific. Under that folder we created folders for each specific environment targeted for deployment, including local development. It looked like this:

Project
\
 -Properties
 \
  -Local (your PC)
  -Dev (shared dev server)
  -Test (pre-production)
  -Prod (Production)

In each folder we put parallel copies of the properties/config files and put the different configurations only in the file in the appropriate folder. The secret was to control the classpath of the deployment environment. We defined a PROPERTIES classpath entry on every server. On Prod, it would be set to "$ProjectDir/Properties/Prod" while on Test the same variable would be set to "$ProjectDir/Properties/Test".

This way we could have database connection strings for the dev/test/prod database preconfigured and not have to checkout/in the property file each time we wanted to build for a different environment.

This also meant that we could deploy the exact same .war/.ear file to Test and Prod without rebuilding. Any properties that weren't declared in the properties file we handled in a similar way by using the same JNDI name in each environment but using values that were specific to that environment.

Kelly French