外部log4j.xml文件 [英] External log4j.xml file
问题描述
我正在尝试在jar外面的文件系统上运行带有log4j.xml文件的jar,如下所示:
I am trying to run a jar with the log4j.xml file on the file system outside the jar like so:
java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=log4j.xml argToJar1 argToJar2
我也尝试过:
java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=/opt/companyName/pathToJar/log4j.xml argToJar1 argToJar2
log4j.xml是文件与jar(/ opt / companyName / pathToJar /)位于同一目录中,但我仍然收到标准警告消息:
The log4j.xml is file is in the same directory as the jar (/opt/companyName/pathToJar/), yet I still get the standard warning message:
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
是否可以将配置文件放在jar外面,或者我是否必须将其打包罐?
Is it possible to have the config file outside the jar, or do I have to package it with the jar?
TIA
推荐答案
使用时-jar
切换到启动可执行jar文件,类路径从jar文件的清单中获取。 -cp
开关(如果给定)将被忽略。
When using the -jar
switch to launch an executable jar file, the classpath is obtained from the jar file's manifest. The -cp
switch, if given, is ignored.
Jeff Storey的答案将是最简单的解决方案。或者,您可以将 Class-Path
属性添加到jar文件的清单。
Jeff Storey's answer is going to be the easiest solution. Alternatively, you could add a Class-Path
attribute to the jar file's manifest.
编辑
尝试启用log4j调试,并使 log4j.xml
的路径成为完全限定的URL。例如:
EDIT
Try enabling log4j debugging, and making the path to log4j.xml
a fully-qualified URL. For example:
java -Dlog4j.debug -Dlog4j.configuration=file:/path/to/log4j.xml -jar ...
这篇关于外部log4j.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!