java:log4j:jar可执行文件有问题 [英] java: log4j: problem with jar executable

查看:88
本文介绍了java:log4j:jar可执行文件有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从命令行运行"java pakcage.Main"时,我的log4j正常运行,但是当我使用"java -jar myjar.jar"之类的可执行jar运行相同程序时,出现以下错误:

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:

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

log4j.jarlog4j.properties在清单的Class-Path中.

我确定它一次可以正常工作,但是在重建之后就无法正常工作.

I'm sure it worked properly once, but after rebuild it is not working.

推荐答案

您只能将jar文件或目录列出为类路径的一部分.应该指定属性文件相对于正在执行的jar的目录,而不是指定log4j.properties.

You can only list jar files or directories as part of a classpath. Instead of specifying log4j.properties you should specify the directory that the properties file is in relative to the jar being executed.

示例:

如果myjar.jar位于基本目录中,则..lib/中的log4j.jar和./conf/中的log4j.properties

If myjar.jar in the base directory, log4j.jar in ./lib/ and log4j.properties in ./conf/

myjar.jar中的Class-Path条目如下

The Class-Path entry in myjar.jar as follows

类路径:lib/log4j.jar conf/

Class-Path: lib/log4j.jar conf/

这篇关于java:log4j:jar可执行文件有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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