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 17:23:58 GMT
Yes, I mean the getSystemResource is a static method.  I call this static
method from another static method....

   static public String formFullPath( String fName )
   {
      URL url;

      if (fName.charAt(0) == '/'){
         System.out.println("fName is " + fName);
         return fName;
      }
      url = ClassLoader.getSystemResource(fName);
      System.out.println("url is " + url);
      return (url == null) ? fName : url.getFile();
   }

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?

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


Bryan Austad wrote:
>
> I use a class with static methods to load properties.  getResource() does
> not return a static URL, so I cannot use it within my static method.
> getSystemResource() returns a static URL.
>

 static URL?

 Do you mean that getSystemResource() is a static method in
ClassLoader? That's true, but you're allowed to call non-static
methods on other objects inside a static method. In fact,
getSystemResource() just gets the system classloader with
getSystemClassLoader() and calls getResource() on it.

 Where are you calling the static methods from? From the init()
of a servlet? If so, you can get the servlet's classloader and
pass it to the static method.


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