File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Reading file from tomcat, outside servelet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading file from tomcat, outside servelet." Watch "Reading file from tomcat, outside servelet." New topic

Reading file from tomcat, outside servelet.

Ranban Smith

Joined: Aug 18, 2011
Posts: 2
I am working on a tomcat application, in which there is a Spring bean which is declared like

<bean name="PleskXMLInputs" class="<FULLY_QUALIFIED_CLASS_NAME>"
<property name="slCacheIdentifier" ref="..."/>

The xml files containing the declarations are declares included in the web.xml, as follows:


Now the above mentioned bean is used somewhere in the web application. The class does not extend servlet, so I can't use the getServletContext() approach. Is there any way I can read a properties file placed somewhere inside the web application (WEB-INF,WEB-INF/classes, META-INF - anywhere is fine) from inside the bean class?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

WEB-INF/classes is part of the classpath of the webapp. So any resources placed there can be loaded the same way they would be in a stand-alone Java application, via the classpath resource loader.

An IDE is no substitute for an Intelligent Developer.
abani patra
Ranch Hand

Joined: Oct 11, 2011
Posts: 70
Hi ,
You can use the following code snippet in the xml file to use properties files:
I agree. Here's the link:
subject: Reading file from tomcat, outside servelet.
It's not a secret anymore!