You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by er...@caldergroup.com on 2006/06/08 01:13:54 UTC

Difference in classloaders

Hi,

I have two questions. I have been working with a stand alone app which  
finds a properties
file this way. This code is in a class, which is bundled in a jar.

private static void setupProperties()
{
     InputStream fileReference =  
ClassLoader.getSystemResourceAsStream(PROPERTIES_FILE);
}

This works fine when run on a command line, but in Tomcat the  
application can not find
the properties file.

I put the following code in a class in a non-static method in a class,  
which is bundled
in a jar. This works find on both the command line and in Tomcat, my  
application can find
the properties file.

private void setupPropertiesInWebapp()
{
     InputStream fileReference =  
this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
}

In Tomcat the properties file lives in  
$CATALINA_HOME/webapp/myapp/WEB-INF/classes/


My Questions are
1) Is there a way to make the first example work in Tomcat, and have  
my application find
the properties file?
2) Why doesn't ClassLoader.getSystemReasourceAsStream work in Tomcat?  
Does it not see the
correct classpath?

Thanks
ERIC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org