Hostname-driven configuration files
This is a technique that has been used in the past with some success, though its limitations of scale and its assumption that you only have one configuration per hostname, do not adapt to the modern world.
- The web.xml file is fixed and cannot be changed.
- The web application contains a set of .properties files in its codebase, each with the name of a specific host.
- All application-specific configuration information is encoded in the properties files
- When the application starts up, it determines its hostname, and loads a properties file that is specific to that hostname
Features
- A machine-specific configuration file is included for every target system.
- The hostname is determined at runtime, and hence the appropriate configuration file is loaded.
Advantages
- A single WAR file can contain configuration information for multiple target systems
- All configuration information is under SCM.
- No need to generate different WAR files for different target systems
Disadvantages
- Cannot configure web.xml-specific options, such as which servlets are to be started.
- A single machine can have only one configuration.
- May have trouble determining the correct hostname on a system with multiple network cards; there is no Java system property 'hostname' to use.
- Does not scale out to farms with many hosts (unless you implement some kind of farm-specific configuration files and have a list mapping hostname to farm file)
- Does not adapt to VM-hosted systems in which hostnames may be the same (VMWare), or in which the hostname is not know until deployment (Xen, Amazon EC2)
SmartFrog support
The disadvantages of this approach are enough to make us unhappy with it. It worked well in 2000-2001, but not now that a laptop can have 4 different hosts underneath, all with the same name as those on a colleagues, and where the production systems are dynamically allocated from a farm of 500 servers. What does work is having a set of property files, and then using a JVM property to select which one to use.