Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using xml config file, don't want to hard code path in config file reader

 
Sakti Singh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,

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?

Eg: String xmlFilePath = "C:\test\test.xml"
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(xmlFilePath), this);

I don't want to hardcode xmlFilePath


My problem will be solved if I can

1. use relative path
2. some kind of class path

else I will have to write another ini file (which will have the xml file path) and place that at root directory

Note that my application supports : AIX, Linux and windows


Appreciate you help..

Namaste,

Sakti
[ June 26, 2004: Message edited by: Sakti Singh ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Is this a web application (a .war file) or a standalone application?
 
Sakti Singh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse, thanks for looking at this:

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 ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

  •  
    Sakti Singh
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You are the Man, thanks Lasse ...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic