user2048204
user2048204

Reputation: 759

Where to place log4j.xml file in a non Maven Project

I have my log4j.xml file stored in the project directory but i am getting following error:

log4j:WARN No appenders could be found for logger (p1.Employee).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.

When i palced it in the bin folder Everything works fine. But i dont check in the bin folder in the code repository so i dont want to place it there.

I dont want to use DOMConfigurator.configure("log4j.xml") as well

Below is my Project Stucture.

enter image description here

Upvotes: 1

Views: 3081

Answers (2)

Ishnark
Ishnark

Reputation: 681

In a normal Java Project, you can place a log4j configuration file, i.e., a log4j.properties or a log4j.xml, in a resources directory. The resources directory should be on the same level as src. Putting it here, will allow log4j to use the configuration file automatically.

Otherwise, you can set the log4j configuration file to use via a VM option by doing something like:

-Dlog4j.configuration=file:///path/to/log4j.xml 

In your case, if you want to place it in the TrailProject project directory, you can do

-Dlog4j.configuration=file:///path/to/TrailProject/log4j.xml

Upvotes: 1

Harneet Singh
Harneet Singh

Reputation: 2556

As per the maven java project folder structure, the ideal path to put the config.xml would be in /src/main/resources directory, so for a non maven project you would put it in an equivalent /resources directory.

Upvotes: 0

Related Questions