views:

1258

answers:

4

In Tomcat (and some other servlet containers) I can store information about my JDBC DataSource in META-INF/context.xml. This is very useful.

However, the settings for my JDBC DataSource can be different in my development and production environments. I'd like to know how other people deal with these differences in an elegant way, specifically how can I set up a context.xml for my development environment and one for my production environment in the most hassle-free manner.

+1  A: 

You can create different files for specific builds. For example, create: development.context.xml production.context.xml

Then, you can control which context file is used in your build.xml file. Basically, setup a prompt for which type of build you would like to use. When you select development, it uses the development context file. When you select production, it uses the production context file.

Kevin Crowell
How well does this work with Eclipe's Dynamic Web Application support?
wrumsby
I am not sure. I am not familiar with using Eclipse for web development. I have only used Netbeans for that. I am sure it is possible though. Ant should be able to handle it.
Kevin Crowell
+1  A: 

Personally I wouldn't store configuration information like that in context.xml (perhaps in another properties file or something), but the general way for something like this is to have your build script package different versions of the configuration file into the WAR/EAR/whatever. You could have your build script decide whether to use the "dev" or "production" configuration file based on parameters you pass in, running different targets, etc.

Something I use often is the task in ant to replace certain tokens in files with values from a filters file; and swap which filters file is used depending on which environment I am targeting.

matt b
+1  A: 

I would do the same as Kevin mentioned. If you're using Maven you would use "profiles".

A: 

If you want to learn more about Maven profiles read this: Introduction to Build Profiles

Daniel Murygin