简体   繁体   English

Jar中的Log4J-属性

[英]Log4J in jar - properties

I have a problem with the log4J in my project. 我的项目中的log4J有问题。 It works fine in Eclipse but when I put it in a runnable jar I get issue's like : 它在Eclipse中可以正常工作,但是当我将其放在可运行的jar中时,会出现类似以下问题:

在此处输入图片说明

My structure looks something like this : 我的结构看起来像这样:

在此处输入图片说明

So I believe there is a problem with loading my Log4J property file's. 因此,我认为加载Log4J属性文件存在问题。

I load them by : 我通过以下方式加载它们:

在此处输入图片说明

This is normally not how you configure log4j. 通常,这不是配置log4j的方式。 Normally, you'd make a file named log4j.properties and not call the PropertyConfigurator at all. 通常,您将创建一个名为log4j.properties的文件,而根本不调用PropertyConfigurator。 You can put that file at the root of your jar, or in an outside directory added to classpath. 您可以将该文件放在jar的根目录中,也可以放在添加到classpath的外部目录中。

They belong in the project CLASSPATH. 它们属于项目CLASSPATH。 If you put the log4j.properties or log4j.xml in the CLASSPATH you'll have no problem finding them. 如果将log4j.properties或log4j.xml放在CLASSPATH中,则查找它们将没有问题。

It's another example of how using Eclipse without knowing what it's doing is harmful. 这是不知道如何使用Eclipse有害的另一个示例。 How many people come here and say "It works fine in Eclipse but fails without it"? 有多少人来这里说:“它在Eclipse中可以正常工作,但如果没有它就失败了”?

property file must be inside the CLASSPATH. 属性文件必须在CLASSPATH中。 there for add it in to the call path by Right Click the Project --> Build Path --> Use as Source Folder Right Click the Project --> Build Path --> Use as Source Folder ,将其添加到调用路径中

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

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