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

Servlet reading config file from ?? path

P: n/a
I have a web application that needs to read an xml configuration file. How
can I specify this without knowing the path of the web application?

I've tried using ClassLoader.getSystemResourceAsStream(filename) but this
doesn't seem to work for my servlet even with the config file in the lib
folder of the web app.

Can anyone give me any pointers?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Moth" <no*@this.address> wrote in message news:<ge******************@news-server.bigpond.net.au>...
I have a web application that needs to read an xml configuration file. How
can I specify this without knowing the path of the web application?

I've tried using ClassLoader.getSystemResourceAsStream(filename) but this
doesn't seem to work for my servlet even with the config file in the lib
folder of the web app.

Can anyone give me any pointers?


I believe any configuration item can be written in WEBINF/web.xml file
and can be read via standard Servlet API methods.
Jul 17 '05 #2

P: n/a


"hiwa" <HG******@nifty.ne.jp> wrote in message
news:68**************************@posting.google.c om...
"Moth" <no*@this.address> wrote in message

news:<ge******************@news-server.bigpond.net.au>...
I have a web application that needs to read an xml configuration file. How can I specify this without knowing the path of the web application?

I've tried using ClassLoader.getSystemResourceAsStream(filename) but this doesn't seem to work for my servlet even with the config file in the lib
folder of the web app.

Can anyone give me any pointers?


I believe any configuration item can be written in WEBINF/web.xml file
and can be read via standard Servlet API methods.


getClass().getResource("/path/from/app/root/to/file.xml")

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
Jul 17 '05 #3

P: n/a
"Moth" <no*@this.address> wrote in message news:<ge******************@news-server.bigpond.net.au>...
I have a web application that needs to read an xml configuration file. How
can I specify this without knowing the path of the web application?

I've tried using ClassLoader.getSystemResourceAsStream(filename) but this
doesn't seem to work for my servlet even with the config file in the lib
folder of the web app.

Can anyone give me any pointers?


I do not know if you are using Tomcat, but if you are I think you
should try to put the file in the /WEB-INF/classes directory of your
application. In this directory you should put classes and resources
that are unpacked. Classes and resources in jar-files should be put in
the /WEB-INF/lib. Classes and resources that are put in these
directories are visible only to the containing web application, but to
no others.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.