You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Johan Dahlström <jo...@RKS.SE> on 2000/07/21 02:04:29 UTC

Please help: Loading...

Hi,

I'm going nuts over Tomcat here... Do any of you with experience with 
Tomcat know why I cannot use getClass().getResourceAsStream() like:

InputStream is=getClass().getResourceAsStream("/app.prop")
Properties prop =new Properties();
try
{
prop.load(is);
} 

to load propertyfiles from the classpath. 
This works 100% when using LiteWebServer (using the exact same
JVM/servlet/classpath etc), but when moving to Tomcat, it seems 
to find the file, but it doesn't load... (Tomcat's FAQ-o-matic 
(http://jakarta.apache.org/jyve-faq/Turbine/screen/DisplayTopics/action/SetA
ll/project_id/2/faq_id/12)
gives no clue on this.)

Has it anything to do with Tomcat's classloader, or am I barking up the
wrong tree by assuming that?

Please help!

Any ideas?

TIA
Regards
Johan D 

Re: Please help: Loading...

Posted by "Edward W. Rouse" <er...@vei.net>.
This is not a direct answer to your question, but...
I never did like loading properties using the getResourceAsStream method. It
gave me problems under JRun. Instead try:

prop.load(new FileInputStream("/app.prop"));

you might need to play with the path to the prop file. I set the path using
servlet contexts, getPath, etc...
Bottom line is, if you can do something without using getClass(), do it.
getClass seems to be one of those methods that doesn't always work exactly the
same way in all situations.
Ed.

Johan Dahlström wrote:

> Hi,
>
> I'm going nuts over Tomcat here... Do any of you with experience with
> Tomcat know why I cannot use getClass().getResourceAsStream() like:
>
> InputStream is=getClass().getResourceAsStream("/app.prop")
> Properties prop =new Properties();
> try
> {
> prop.load(is);
> }
>
> to load propertyfiles from the classpath.
> This works 100% when using LiteWebServer (using the exact same
> JVM/servlet/classpath etc), but when moving to Tomcat, it seems
> to find the file, but it doesn't load... (Tomcat's FAQ-o-matic
> (http://jakarta.apache.org/jyve-faq/Turbine/screen/DisplayTopics/action/SetA
> ll/project_id/2/faq_id/12)
> gives no clue on this.)
>
> Has it anything to do with Tomcat's classloader, or am I barking up the
> wrong tree by assuming that?
>
> Please help!
>
> Any ideas?
>
> TIA
> Regards
> Johan D