简体   繁体   English

如何在Eclipse中的项目类路径中添加log4j.properties文件的路径?

[英]How to add path of log4j.properties file in my project classpath in eclipse?

I have a package called Resources in which I have placed my log4j.properties file. 我有一个名为Resources的软件包,其中已放置了log4j.properties文件。 When I run my code, I get the following error: 运行代码时,出现以下错误:

log4j:WARN No appenders could be found for logger. log4j:WARN找不到记录器的附加程序。
log4j:WARN Please initialize the log4j system properly. log4j:WARN请正确初始化log4j系统。

How should I update the classpath to include Resource folder ? 我应该如何更新类路径以包括Resource文件夹?

Solution tried: 解决方案尝试:
I added the log4j.properties file directly under 'source' and it worked. 我直接在“源”下面添加了log4j.properties文件,它可以正常工作。

Here is the contents of properties file: 这是属性文件的内容:

#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=C:\\Users\\kagarwal\\Desktop\\Application.log
log4j.appender.dest1.Append=false

Right click on the folder, select Build Path then Use as a Source Folder . 右键单击该文件夹,选择“ Build Path然后Use as a Source Folder

Just remember that when you will deploy you will need to create a directory for resources and add it to class path. 只需记住,在部署时,您将需要创建资源目录并将其添加到类路径。

You should also consider to use maven for your java project, it may seem overkill initially but it will pay off in the long run. 您还应该考虑将maven用于Java项目,起初看似过高,但从长远来看会有所回报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM