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.
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.