The question is - what class loader loaded the class this is being
called from?  The getClass().getResourceAsStream doesn't magically know
about resources that are not loaded with its own classloader or one of its
parents.  So, app.properties and the class that you are trying to load this
from must be loaded from the same classloader, which means that they both
must either be in the CLASSPATH, or the %TOMCAT_HOME/{lib|classes}, or
WEB-INF/{lib/classes}.  If the class is "higher up" in the classpath then it
won't be able to find the properties file.

        Randy

> -----Original Message-----
> From: Richard Sand [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 22, 2001 8:38 AM
> To: [EMAIL PROTECTED]
> Subject: getResourceAsStream doesn't find files in WEB-INF/classes
> 
> 
> Hi- I've deployed an application with Tomcat at the root 
> (i.e. "/").  At one
> point I load a resource file with the command:
> 
> InputStream is = getClass().getResourceAsStream("/app.properties");
> 
> But Tomcat throws an exception here if the file 
> app.properties is in the
> /WEB-INF/classes directory.  If I copy it into a directory 
> that is in the
> default CLASSPATH, then it works fine.  Isn't the 
> WEB-INF/classes directory
> for each deployed application automatically added to the 
> Tomcat classpath?
> Is the behavior I'm seeing the expected behavior?
> 
> I hope I'm just doing something thick... otherwise, its more 
> problematic to
> be able to bundle up an application, because the resource 
> files would need
> to be copied somewhere else.  Any advice?
> 
> BTW Tomcat 3.2.2 on Win2k, no web server (i.e. Tomcat 
> default, port 8080).
> 
> Thanks!
> 
> -Richard
> 

Reply via email to