Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

java - Should log4.properties be on the classpath?

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.

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

And then with put the JAR on this file organization:

folder
  |-------- app.jar
  |-------- lib
             |--------- log4j.properties
             |--------- log4j-1.2.15.jar

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.

My log4j.properties file it's like this:

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}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

one more way to do this: -Dlog4j.configuration=file:"./log4j.properties"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...