tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Austad" <baus...@xtendsoft.com>
Subject RE: Loading property files using ClassLoader.getSystemResource()
Date Wed, 13 Feb 2002 19:06:02 GMT
Thank you Christopher and Craig,
  I used the 
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
  This worked great! I appreciate the help.

Bryan

-----Original Message-----
From: Christopher K. St. John [mailto:cks@distributopia.com]
Sent: Wednesday, February 13, 2002 11:25 AM
To: Tomcat Users List
Subject: Re: Loading property files using
ClassLoader.getSystemResource()


Bryan Austad wrote:
> 
> I call this static method from another static method.. When
> I try using ClassLoader.getResource(fName), I get a compile
> error: non-static method getResource(java.lang.String) cannot
> be referenced from a static context
> 
> How do I get around this?
> 

 The simplest correct way is to just keep adding ClassLoader
params all the way up until you get to a non-static method. 

 If you're absolutely 100% sure that the classes with the
static methods will be loaded with the same classloader as
the servlet, then you can do something like:

  ClassLoader cl = MyClass.class.getClassLoader();
  cl.getResource(someResource);

 If the classes with the static methods might be loaded
from a different classloader (like if you put them in the
CATALINA_HOME/shared), then you'll run into a problem. In
that case, you need to something like:

   ClassLoader cl = Thread.currentThread().getContextClassLoader();

 But, personally, I'd avoid the whole context class loader
thing if at all possible. Even if you read all the docs and
understand it, chances are the next person who looks at your
code will be totally mystified.

-- 
Christopher St. John cks@distributopia.com
DistribuTopia http://www.distributopia.com

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message