By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,778 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,778 IT Pros & Developers. It's quick & easy.

loading config file

P: n/a
Probably a simple question. I've written a web app that loads configuration
info from an xml file. What is the best way to tell my app where that file
is located? This app needs to run on both windows on linux machines...
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Moth wrote:
Probably a simple question. I've written a web app that loads configuration
info from an xml file. What is the best way to tell my app where that file
is located? This app needs to run on both windows on linux machines...

there are a lot of solutions for this issue,
but I'll just give you the ones I would use myself.

1 - Place the file in the WEB-INF directory and call it from your
servlet and/or jsp file with:

getServletContext().getResourceAsStream("/WEB-INF/<your config file>");

or

getClass().getResourceAsStream("/WEB-INF/<your config file>");

2 - Place it in the classes directory under WEB-INF and
call:

getClass().getResourceAsStream("/<your config file>"");
Hope it helps,
Lau.
Jul 17 '05 #2

P: n/a
Moth wrote:
Probably a simple question. I've written a web app that loads configuration
info from an xml file. What is the best way to tell my app where that file
is located? This app needs to run on both windows on linux machines...


Place the file in the CLASSPATH and use ClassLoader.getResource(). This
will work in all environments (servelt, applet, application, etc.).

Ray

Jul 17 '05 #3

P: n/a
"Moth" <no@email.here> wrote in message news:<gW****************@news-server.bigpond.net.au>...
Probably a simple question. I've written a web app that loads configuration
info from an xml file. What is the best way to tell my app where that file
is located? This app needs to run on both windows on linux machines...

Use Class#getResourceAsStream(), and preferably, you might want to
make a war file.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.