This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to put log4j.properties file in visual web jsf

 
baran tamer
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, what does the java doc for that method say? Where does it start looking for that resource from?
 
baran tamer
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I'm not 100% familiar with this, but have you tried placing it in the WEB-INF/classes directory?
 
baran tamer
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic