简体   繁体   English

java:log4j:jar可执行文件的问题

[英]java: log4j: problem with jar executable

My log4j is working fine when I run "java pakcage.Main" from command line, but when I run the same program using executable jar like "java -jar myjar.jar" I'm getting the following err: 当我从命令行运行“java pakcage.Main”时,我的log4j工作正常,但是当我使用像“java -jar myjar.jar”这样的可执行jar运行相同的程序时,我得到以下错误:

log4j:WARN No appenders could be found for logger
log4j:WARN Please initialize the log4j system properly

log4j.jar and log4j.properties are threre in my manifest's Class-Path . log4j.jarlog4j.properties位于我的清单的Class-Path

I'm sure it worked properly once, but after rebuild it is not working. 我确定它一次正常工作,但重建后它无法正常工作。

You can only list jar files or directories as part of a classpath. 您只能将jar文件或目录列为类路径的一部分。 Instead of specifying log4j.properties you should specify the directory that the properties file is in relative to the jar being executed. 您应该指定属性文件相对于正在执行的jar的目录,而不是指定log4j.properties。

Example: 例:

If myjar.jar in the base directory, log4j.jar in ./lib/ and log4j.properties in ./conf/ 如果基目录中的myjar.jar,。/ lib /中的log4j.jar和./conf/中的log4j.properties

The Class-Path entry in myjar.jar as follows myjar.jar中的Class-Path条目如下

Class-Path: lib/log4j.jar conf/ 类路径:lib / log4j.jar conf /

I believe you should also be able to simply include your log4j.xml (or log4j.properties) file inside of your custom Jar file. 我相信您还应该能够在自定义Jar文件中包含log4j.xml(或log4j.properties)文件。 As long as it is in the root of your Jar file, the log4j framework will be able to find it. 只要它位于Jar文件的根目录中,log4j框架就能找到它。

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

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