java: log4j: problem with jar executable

南楼画角 提交于 2019-12-23 12:17:04

问题


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.jar and log4j.properties are threre in my manifest's Class-Path.

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


回答1:


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.

Example:

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

The Class-Path entry in myjar.jar as follows

Class-Path: lib/log4j.jar conf/




回答2:


I believe you should also be able to simply include your log4j.xml (or log4j.properties) file inside of your custom Jar file. As long as it is in the root of your Jar file, the log4j framework will be able to find it.




回答3:


Does this help ?

http://marc.info/?l=log4j-user&m=105168892203831&w=3



来源:https://stackoverflow.com/questions/7215462/java-log4j-problem-with-jar-executable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!