aspose file tools*
The moose likes Other Open Source Projects and the fly likes where to put log4j.properties file in visual web jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "where to put log4j.properties file in visual web jsf" Watch "where to put log4j.properties file in visual web jsf" New topic
Author

where to put log4j.properties file in visual web jsf

baran tamer
Ranch Hand

Joined: Jan 22, 2009
Posts: 33
Hello ,

I have used log4j in several projects just by putting log4j.properties in my default source package.
This time i am using below command (I am using netbeabs ide 6.5.1)



This time the server is saying "java.io.FileNotFoundException: log4j.properties (No such file or directory)"

I have tried default package , root folder , and the web pages folder.

What do you think would be the problem ?

Thanks

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK, what does the java doc for that method say? Where does it start looking for that resource from?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
baran tamer
Ranch Hand

Joined: Jan 22, 2009
Posts: 33
if you mean this one

As of log4j version 0.8.5, at class initialization time class, the file log4j.properties will be searched from the search path used to load classes. If the file can be found, then it will be fed to the configure(java.net.URL) method.


I am guessing this is used for initialization, and looking for log4j.properties in the classpath.
But i am trying to override that config file by using



and javadoc doesnt say how PropertyConfigurator.configure behaves
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hmm, I'm not 100% familiar with this, but have you tried placing it in the WEB-INF/classes directory?
baran tamer
Ranch Hand

Joined: Jan 22, 2009
Posts: 33
I have solved it by putting the file in the working config directory at that moment.

which is home/glassfish-v2.1/domains/domain1/config for glassfish.

If mine was a java application it would have worked as i wrote above , however in a web application that is runnning on glassfish you either have to put the properties file in

home/glassfish-v2.1/domains/domain1/config
or give the full path to the function
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi,
I think whatever the App server we use, the log4j.properties file for any application should be inside the directory structure of that application.
Like if we have a webapplication then as Martijn said , the best location would be "WEB-INF\classes". It might be the way we load the properties file that would cause the problem of not finding the log4j.properties file.
I faced this problem couple of times but resolved it using

inside ServletContextListener.
getResourceAsStream() looks for the file in classpath and hence can find one if put in "WEB-INF\classes" directory.

Regards,
Amit
 
Don't get me started about those stupid light bulbs.
 
subject: where to put log4j.properties file in visual web jsf