This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using an xml file as my initial config file. I don't want to hard code the aboslute path of the xml file in xml file reader class. Is there any way I can tell the xml path to my config xml file reader?
Lasse>Is this a web application (a .war file) or a standalone application?
Sakti> This is a web app, .war file
Lasse> Is the user supposed to edit this configuration file at some point or is it a "static" configuration that the user doesn't even know about?
Sakti> The xml file should be modified only at the time of deployment.
This xml file has ini variables like: dbuser, dbpassword, schema, mailserver, adminid, approverid et al
Which may be modified after deployment as well. So I would say its not a "static" configuration. [ June 27, 2004: Message edited by: Sakti Singh ]
Joined: Jan 23, 2002
Ok. Because you need to update the file at runtime, you can't really use the classpath for looking it up. Therefore, I'd suggest the following:
Add a "context-param" into your web.xml, which points to the absolute location of your custom configuration file.
Write a ServletContextListener which, upon startup, reads the context-param (the file path), and creates an object that 1) serves as the "configuration repository" from which other classes can ask the configuration properties, and 2) refreshes its data from the filesystem every now and then to keep in sync with the actual configuration file.