Hello Charles,

I am using a war file named sample.war to deploy my sample application in
tomcat 6.0. I have my log4j.properties file with that exact name in
WEB-INF/classes folder. That is I copy the war file into webapps folder of
tomcat and when I run tomcat it gets explode into folder sample, so I have
the log4j.properties file under in the following path
webapps/sample/WEB-INF/classes/log4j.properties.

Now 
1) when I say PropertyConfigurator.configure("log4j.properties"); I get FNF
exceptions.
2) If I dont say PropertyConfigurator.configure("log4j.properties") in my
servlet init code a directly take a logger instance say
Logger.getlogger(Sample.class); the logging goes on fine.

Note: I have my log4j.jar inside WEB-INF/lib folder and not in tomcat's lib
folder. 


Caldarale, Charles R wrote:
> 
>> From: jkv [mailto:j.kumara...@gmail.com]
>> Subject: RE: FileNotFoundException in Tomcat6.0
>> 
>> But the problem starts only if you try to configure using a
>> PropertyConfigurator having the same file there and use the 
>> above statement then you get FNFExe because the classpath is
>> acutally bin folder of Tomcat and log4j searches the bin 
>> folder for a log4j.configuration which is actually strange.
> 
> I'm not sure I believe that - log4j should be using the webapp's
> classloader, not the system classloader.  Sounds like a bug in log4j or
> how you have it installed.
> 
> "The getRealPath() method should never be relied upon; the container is
> under no obligation to return anything here.  For example, if your webapp
> is packaged as a .war file, it will return null." -> But I am using a war
> file and I get a valid value instead of null in tomcat. I am getting real
> path up to my application context root say c:/tomcat/webapps/sample/. To
> my knowledge I havent touched any configuration values in tomcat, but I
> will anyways re-check.
> 
> Regards
> jkv
> 
>> So you will have to use this statement 
>> PropertyConfigurator.configure(servletContext.getRealPath("/") +
>> "/WEB-INF/classes/" + "log4j.properties");
> 
> The getRealPath() method should never be relied upon; the container is
> under no obligation to return anything here.  For example, if your webapp
> is packaged as a .war file, it will return null.  You need to fix the
> problem in your log4j setup, not attack the symptom.
> 
>> The similar is the case for any file in Tomcat, ie is if you want to
>> read from a custom file in tomcat say your own configurations for web
>> application the you will have to use the Path for the file using the
>> servletContest.getRealPath("/") + ... your expected file path starting
>> from root.
> 
> That's definitely not true - the classloader path for any thread running
> inside a webapp is WEB-INF/classes and WEB-INF/lib first, followed by the
> shared library, and only then the system classpath.  Something you're
> doing is breaking the classloader model implemented by Tomcat:
> http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
> 
>  - Chuck
> 
> 
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/FileNotFoundException-in-Tomcat6.0-tp26808548p26842784.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to