未从jar拾取log4j.properties [英] log4j.properties not picked up from jar

查看:79
本文介绍了未从jar拾取log4j.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器的类路径中有一个jar,在jar的根目录中包含log4j.properties文件,用于记录代码.当jar中的代码运行时,不会记录该代码.当我使用 java -Dlog4j.debug 选项分析问题时,我知道log4j正在加载 axis-ant.jar 的log4j.properties文件(这也是在我的类路径上)并使用它而不是jar的属性文件.

I have a jar in the classpath of my server which contains the log4j.properties file on root of the jar for logging of the code. When the code in the jar runs the logging for the code is not occuring. When I analyzed the problem using java -Dlog4j.debug option I got to know that the log4j is loading the log4j.properties file of axis-ant.jar (this also is on my classpath) and using it instead of my jar's property file.

当我随后从类路径中删除axis-ant.jar时,立即选择了jars log4j.properties文件,并记录了我的代码.

When i subsequently removed the axis-ant.jar from the classpath my jars log4j.properties file was picked immediately and logging for my code occured.

有人可以解释为什么在存在axis-ant.jar时为什么不加载我的log4j.properties文件吗?

令人惊讶的是,具有classpath中存在axis-ant.jar的同一个jar在另一台服务器上以正确的日志记录运行成功.

Surprisingly the same jar with axis-ant.jar present in classpath is running with proper logging successfully in another server.. both the server have the same java 5 version installed and same version of log4j jar

推荐答案

您应该看看log4j.configuration)的可能性.

You should have a look at the log4j manual. The section "Default Initialization Procedure" describes how log4j will try to find the initialization file and explains possibilities to match a special configuration (e.g. by setting the system property log4j.configuration).

如果不想执行任何特殊配置,则必须确保配置文件将是在类路径中找到的第一个文件.

If you do not want to do any special configuration you have to ensure that your configuration file will be the first one found on the classpath.

这篇关于未从jar拾取log4j.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆