本文介绍了使用JAR加载log4j.properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有以下清单的jar文件
I have a jar file with the following Manifest
Manifest-Version: 1.0
Created-By: 1.7.0_07 (Oracle Corporation)
Main-Class: test.Main
Class-Path: ./log4j.properties lib/log4j-1.2.17.jar
我按如下方式运行课程
java -jar test.jar
这是我的文件夹
lib
log4j.properties
test.jar
为什么我看不到log4j属性文件?这就是我所看到的
Why I can't see the log4j properties file? This is what I see
log4j:WARN No appenders could be found for logger (test.Main).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
谢谢
解决方案:
将MANIFEST中的classhpath更改为此
SOLUTION:changed my classhpath in the MANIFEST to this
Class-Path: . lib/log4j-1.2.17.jar
推荐答案
你可以还可以使用参数启动JVM:
You can also start your JVM with argument:
-Dlog4j.configuration=file:"./your/properties/path/log4j.properties"
指定外部日志属性的任意位置。我在一个特定项目中经常使用它。
to specify arbitrary location of your external log properties. I used this a lot in one particular project.
这篇关于使用JAR加载log4j.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!