log4j.properties没有从jar中提取出来。[英] log4j.properties not picked up from jar

本文是小编为大家收集整理的关于log4j.properties没有从jar中提取出来。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在服务器的类Path中有一个JAR,其中包含log4j.properties文件,以记录代码.当JAR中的代码运行时,未发生代码的日志记录.当我使用 java -dlog4j.debug 选项分析问题时,我知道log4j正在加载log4j.properties axis -ant.jar.jar.jar.jar.jar.jar.jar (这也是在我的class路径上)并使用它代替我的jar的属性文件.

随后我从classpath中删除轴 - ant.jar时,我的jars log4j.properties文件立即被选中并进行记录.

有人可以解释为什么我的log4j.properties在轴上没有加载.

出乎意料的是,在ClassPath中存在的JAR的Jar同一JAR正在运行,并在另一台服务器中成功登录.这两个服务器都安装了相同的Java 5版本,并且相同的版本是Log4J Jar

推荐答案

您应该看看 log4j 手册. "默认初始化过程"部分描述了log4j将如何尝试找到初始化文件,并解释了匹配特殊配置的可能性(例如,通过设置System属性log4j.configuration).

如果您不想执行任何特殊配置,则必须确保您的配置文件将是Class Path上的第一个.

其他推荐答案

根据您的应用程序服务器在ClassPath中找到JAR的顺序,从JAR拾取了属性文件.现在,没有办法最终告诉插座要加载属性文件.

要解决这个问题,大多数项目将您的log4j.properties文件包含在服务器类路径本身中.这样,此文件是第一个要加载的属性文件,这是您的记录代码获取的文件.

其他推荐答案

我很确定,但这可能是一个订单问题. log4j.properties首先加载/最后一个会赢(我必须检查).

本文地址:https://www.itbaoku.cn/post/1574763.html

问题描述

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.

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.

Can somebody please explain why is my log4j.properties fle not being loaded while axis-ant.jar is present?

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

推荐答案

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.

其他推荐答案

The properties file is picked up from the jar based on the order in which the jar is found in classpath by your application server. Now there is no way to conclusively tell the jar from which the properties file is to be loaded.

To get around this problem most projects include your log4j.properties file in the server classpath itself. This way this file is the first properties file to be loaded and this is the one which your logging code gets.

其他推荐答案

I'm note quite sure but it could be an order problem. Whichever log4j.properties is loaded first/last would win (I'd have to check that).