Meaningless Drivel is fun!
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

Win a copy of The Software Craftsman this week in the Agile forum!
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: 16540

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
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:
Have you tried LearnNowOnline?
subject: Reading file from tomcat, outside servelet.