We do this to put it in a separate directory on the server (you can use something like / config, / opt / config, / root / config, / home / username / config or whatever). When our servlets start, they read the XML file, extract a few things from it (most importantly, information about connecting to the DB) and what it is.
I asked why we did it once.
It would be nice to store everything in the database, but obviously you cannot store information about connecting the database to the database.
You can hardcode the code in code, but this is ugly for many reasons. If the information ever needs to change, you need to rebuild the code and redeploy. If someone receives a copy of your code or your WAR file, they will then receive this information.
Putting things in a WAR file seems nice, but if you want to change a lot, it might be a bad idea. The problem is that if you need to change the information, then the next time you redeploy it, it will overwrite the file so that everything that you do not remember is forgotten to change the version built into the WAR.
A file in a special place on the file system works pretty well for us. He has no big flaws. You know where it is located, it is stored separately, it simplifies deployment on several machines if they all need different configuration values โโ(since they are not part of the WAR).
The only other solution that I can think of that this will work well is to store everything in the database, except for the entry information in the database. This comes from Java system properties that are retrieved through the JVM. This is the settings API mentioned by Hans Doggen above. I donโt think it was around when our application was first developed if it werenโt used.
As for the access path to the configuration file, it is just a file in the file system. You do not need to worry about the web path. So when your servlet starts up, it just opens the file in the /config/myapp/config.xml file (or something else) and it will find the right thing. Just hardcodeing the way for this seems completely harmless to me.
MBCook Sep 18 '08 at 20:15 2008-09-18 20:15
source share