[英]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.xml文件存储在项目目录中,但出现以下错误:
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. 当我将其放在bin文件夹中时,一切正常。 But i dont check in the bin folder in the code repository so i dont want to place it there.
但是我不签入代码存储库中的bin文件夹,所以我不想将其放在那里。
I dont want to use DOMConfigurator.configure("log4j.xml") as well 我也不想使用DOMConfigurator.configure(“ log4j.xml”)
Below is my Project Stucture. 以下是我的项目结构。
In a normal Java Project, you can place a log4j configuration file, ie, a log4j.properties
or a log4j.xml
, in a resources
directory. 在普通的Java项目中,您可以将log4j配置文件(即
log4j.properties
或log4j.xml
)放置在resources
目录中。 The resources directory should be on the same level as src
. 资源目录应与
src
处于同一级别。 Putting it here, will allow log4j to use the configuration file automatically. 将其放在此处,将允许log4j自动使用配置文件。
Otherwise, you can set the log4j configuration file to use via a VM option by doing something like: 否则,您可以通过以下操作将log4j配置文件设置为通过VM选项使用:
-Dlog4j.configuration=file:///path/to/log4j.xml
In your case, if you want to place it in the TrailProject project directory, you can do 对于您的情况,如果要将其放置在TrailProject项目目录中,可以执行
-Dlog4j.configuration=file:///path/to/TrailProject/log4j.xml
根据maven java项目文件夹结构,放置config.xml的理想路径是在/src/main/resources
目录中,因此对于非maven项目,您可以将其放置在等效的/resources
目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.