• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You are the Man, thanks Lasse ...
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic