The Riot Configuration System
Supporting deployment to different environments
Usually an application requires different configurations depending on the environment where it is deployed. On the production system you'll probably have different JDBC settings than in your development environment. Sometimes you might even want to use a completely different RDBMS, let's say an in-memory HSQL-DB for development and a PostgreSQL database on the live server.
This is often the same for Log4J properties. During development you want certain debug messages written directly to your console, but on the production server warnings and errors should be written to a logfile that is automatically rotated.
If you are working in a team, some settings will probably be different for each developer whereas others are shared among the team members.
Configuration Profiles
The Riot configuration system allows you to keep all the different settings under source control. Therefore the project-skeleton provides a folder called /conf.
This folder contains sub-folders for the different configurations and a special folder called default that - as the name suggests - provides default values which are shared among all profiles unless they are overwritten. When you invoke a target of the Ant build file, you can specify which profile should be used:
This command will create a WAR file that contains the default properties merged with the ones defined in Joe's personal profile.
If “joe” was Joe's actual user name he could ommit the -Dprofile=joe argument, as the profile name defaults to ${user.name}.
Property files
So far we've only talked about directories. But since we want to define configuration properties we need some files which contain the actual values.
By default the configuration system looks for these two files: application.properties and log4j.properties.
Both are regular Java property files in the format specified by Sun. The first one contains properties which are read by a Spring PropertyPlaceholderConfigurer in order to configure the application. The latter one is used set up the Log4J logging framework.
Here's a line taken from the file /conf/default/log4j.properties:
Joe could now change the logging behaviour by putting a log4j.properties files into the directory /conf/joe:
log4j.logger.foo.bar=DEBUG
As you can see, he can not only overwrite existing properties but also add new ones. All properties Joe does not specify in his personal log4j.properties are taken from the corresponding default file.
Usage notes
When you modify a .properties file in the /conf folder, the configure Ant target must be executed in order to re-create the merged files.
When you execute any other target, this will be done automatically since all targets depend on the configure target.
The merged files are created in the directory /build/conf. If you run your application from within Eclipse, make sure that this folder is defined as Source Folder. This way the files will automatically end up in /webapp/WEB-INF/classes.
Rember to refresh your project (Select the project ant hit F5 in Eclipse), so that your IDE can pick up the modified files.