It is useful to bunch configuration values together in a single file (or at least in as few files as possible). This not only simplifies maintenance, but it also increases security because you know exactly which files to back up. In UNIX, you can provide higher security by assigning authorization rights for configuration files.
There is always a question as to which is the most elegant way to access the data. Naturally, you can read the files each time you need a value, but this does not lead to high performance, plus you will end up with a lot of redundant code this way. A Singleton Design Pattern (see Glossary) works well in most cases.
Create a new directory called WEB-INF/classes/tools
. Create a class named PropertiesSingleton.java
here and enter the code shown in Listing 5.1. This class originates from one of the open-source projects (http://sourceforge.net/projects/swiesnerxmlgui) and has been used in a lot of projects since.
The constructor is declared private
so that...