aspose file tools*
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
Author

Reading file from tomcat, outside servelet.

Ranban Smith
Greenhorn

Joined: Aug 18, 2011
Posts: 2
Hi,
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>"
depends-on="registered_shared_ServiceLayersCache">
<property name="slCacheIdentifier" ref="..."/>
</bean>

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

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring_context.xml
</param-value>
</context-param>

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: 16061
    
  21

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file from tomcat, outside servelet.