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 [EMAIL PROTECTED] DistribuTopia http://www.distributopia.com -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>
