Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, Not sure if this is the correc

Status
Not open for further replies.

furan

Programmer
Aug 17, 2001
17
0
0
GB
Hi,
Not sure if this is the correct forum, but is my first post - so feel free to redirect me...
Here's the problem.
I've created a webapp packaged as a war, to run it needs to access a property file which contains information for the different app servers it may be deployed on (Websphere, WebLogic, Tomcat). I can get it to load this property file fine if I hard code the location for each app server. However, what I'd like to do is use the ClassLoader to get the Resource as a Stream. I can't get it to find the properties file.

Here's the Package structure:
index.jsp
properties/projectweb.properties
WEB-INF/classes/projectweb/servlet/BuildProjectWeb.java
WEB-INF/classes/projectweb/servlet/ResourceAnchor.java

ResourceAnchor is an empty class with a simple constructor with no implementation. It is used so the ClassLoader can get reference to it's location.

Here's the code:
//Load Properties File
ClassLoader cl = ResourceAnchor.class.getClassLoader();
Properties prop = new Properties();
try
{
prop.load( cl.getResourceAsStream("properties/projectweb.properties") );
}
catch( IOException ioex )
{
System.err.println( "*** IOException : failed to load properties: " + ioex.toString() );
}
catch (Exception ex )
{
System.err.println( "*** Exception : failed to load properties: " + ex.toString() );
ex.printStackTrace();
}

Can anyone see why it always catches the Exception (not the IOException) and provide any help as to how I might fix this. Been trying for over a day now and it's getting to me!

Any help appreciated.

Stuart.

 
What is the exception type thrown.....
is it actually Exception type.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top