When it comes to loading files from the classpath, note the difference between

         myClass.getClassLoader().getResource()

and

         myClass.getResource()

The former loads wrt to the classpath root, but the latter loads wrt to the 
location of the class bytecode file (typically).

i.e., if myClass = com.acme.MyClass

         myClass.getClassloader().getResource("abc.def") => 
<classpathroot>/abc.def

         myClass.getResource("abc.def") => <classpathroot>/com/acme/abc.def

On the specific tomcat issue, if log4j.jar is in the tomcat top-level 
classpath ($TOMCAT_HOME/lib), then neither method will be able to locate 
"log4j.properties" in <webapp>/WEB-INF/classes.   The top-level classloader 
has no access to the private web-app classpath, unless it's given an 
explicit handle.

The solution is either to put log4j.jar and log4j.properties in the tomcat 
classpath, OR both in the web-app.    Any log4j.jar in the tomcat classpath 
will take precedence.

Fergus

At 17:25 30/05/2001 +0100, Steve Meyfroidt wrote:
>Hi,
>
>[[[A disclaimer: I've searched the archives for the solution to this but
>found nothing that I like. And Bugzilla is down too, so I'm sorry if this
>has been covered to death in this list.]]]
>
>I'm having trouble with init of log4j for a servlet running in Tomcat. log4j
>can't find the default config file, "log4j.properties".
>
>The reason for this appears to be that log4j looks for
>      static public final String DEFAULT_CONFIGURATION_FILE =
>"log4j.properties";
>by default, when it should really be looking for "/log4j.properties". The
>slash prefix is significant when loading resources from the classpath. I
>think this would solve the problems that I see other people have been
>having.
>
>Has this been discussed? Am I on the right track? Is it a bug? Can I submit
>it?
>
>Regards,
>Steve Meyfroidt
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Fergus Gallagher
Orbis
http://www.orbisuk.com/
+44-(0)20-8742 1600


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to