log4.properties应该在类路径上吗? [英] Should log4.properties be on the classpath?
问题描述
我在将log4j.properties文件放在classpath上时遇到了一些问题。我可以在开发时使用它(Eclipse Indigo)但是,当我将我的应用程序导出为JAR时,我不能。
I'm having some problems putting my log4j.properties file on classpath. I can use it when I'm developing (Eclipse Indigo) but, when I export my app as a JAR, I can't.
我手工制作导出的JAR的MANIFEST.MF文件:
I've made by hand a MANIFEST.MF file for the exported JAR:
Manifest-Version: 1.0
Main-Class: main.Program
Class-Path: lib/log4j.properties lib/log4j-1.2.15.jar
然后把JAR放在这个文件组织上:
And then with put the JAR on this file organization:
folder
|-------- app.jar
|-------- lib
|--------- log4j.properties
|--------- log4j-1.2.15.jar
当我尝试运行app.jar时,他们找到log4j.jar但不是log4j.properties:
When I try to run app.jar, they find log4j.jar but not log4j.properties:
log4j:WARN No appenders could be found for logger (main.Program).
log4j:WARN Please initialize the log4j system properly.
我的 log4j.properties 文件就像这样:
log4j.rootLogger=INFO, stdout, file
PATTERN=[%d] [%p] [%c{1}]: %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=${PATTERN}
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=${logger_file_path}
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=${PATTERN}
推荐答案
不要将 log4j.properties
本身放在类路径中,而是包含该文件的目录。
Do not put the log4j.properties
itself in the classpath, but the directory that contains that file.
Class-Path: lib lib/log4j-1.2.15.jar
这篇关于log4.properties应该在类路径上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!