I want to read log4j.xml file which is outside the jar inside etc folder. So i created manifest file as follows
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Built-By: Administrator
Main-Class: com.him.LogPrinter
Class-Path: ./lib/log4j.jar ./etc/log4j.xml
My class file is as follows
package com.him;
import org.apache.log4j.Logger;
public class LogPrinter {
/**
* @param args
*/
public static Logger logger = Logger.getLogger(LogPrinter.class);
public static void main(String[] args) {
logger.debug("I am a debug message");
logger.info("i am a info message");
logger.error("i am a error message");
logger.warn("i am a warn message");
System.out.println("hello");
}
}
when i run my jar file using
java -jar myapp.jar
it shows usual exception of no appender could be found for logger and no log file generated.
When I put log4.xml file inside jar file it gives the required output.
Please help I am not able to figure out why configuration file is not picked even if it is in classpath configured using manifest.mf file.
Thanks in advance.
You would need to specify the directory, not the file; like a normal classpath.
I’m not sure I like this idea, though; I think it would be more convenient to supply a config file path on the command line.