Hi,
Iam using Log4j first time and when i run the program through WSAD 5.1.0, it runs fine. But for deployment, when i make it jar and run it from command prompt it throws me following error. Iam using log4j-1.2.9.jar and
java version 1.4.2. Class path is set correct. Your immediate help is highly appreciated.
java -jar SampleJarDP.jar
Exception in
thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Category
Following are properties file and java program.
Properties file
================
#Default log level to ERROR. Other levels are INFO and DEBUG.
log4j.rootLogger=DEBUG, ROOT
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
log4j.appender.ROOT.File=sample.log
log4j.appender.ROOT.MaxFileSize=1000KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#Format almost same as WebSphere's common log format.
log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
Program
=======
import org.apache.log4j.*;
public class Sample {
public static void main(
String[] args) {
int a = 10;
int b = 20;
int c = 0;
System.setProperty("log4j.configuration","log4j.properties");
Logger logger = Logger.getLogger(SampleJar.class.getName());
System.out.println("Value of a : " + a);
System.out.println("Value of b : " + b);
System.out.println("Value of c : " + c);
//
logger.info("Got Logger Object");
logger.info("Value of a : " + a);
logger.info("Value of b : " + b);
logger.info("Value of c : " + c);
a++;
b++;
logger.info("Value of a : " + a);
logger.info("Value of b : " + b);
c = a + b;
logger.info("Value of c : " + c);
}
}