如何停止在控制台上打印log4j FileNotFound错误?

时间:2019-02-07 06:25:38

标签: java log4j executable-jar

我创建了一个实用程序,用于将一些文本数据移至SQL数据库中,并已实现了用于调试目的的日志记录(log4j)。 一旦创建了一个我的实用程序的jar并调用它来执行,该实用程序就可以正常工作,但是每次输出之前都会出现以下错误消息:

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:306)
        at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
        at spotfire.loadtest.Driver.main(Driver.java:28)
log4j:ERROR Ignoring configuration file [log4j.properties].
log4j:WARN No appenders could be found for logger (spotfire.loadtest.Driver).
log4j:WARN Please initialize the log4j system properly.

请注意,我的实用程序有效,并且文本已插入数据库中。我面临的唯一问题是如何摆脱此错误消息。有什么办法可以完全停止打印?

1 个答案:

答案 0 :(得分:0)

您的log4j.properties必须位于类路径中,或者需要将其指定为JVM Argument as

-Dlog4j.configuration = {文件路径}