• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4J NoClassDefFoundError

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}
}
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Class path is set correct.

No, it isn't. If it were correct you wouldn't be getting that error.

Because you have an executable jar file and you are running it using "java -jar", the classpath that is relevant is the Class-Path entry in the manifest inside your SampleJarDP.jar file. I am guessing you set an environment variable and believed that would apply.
 
Sreenivasulu Naidu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul for your quick reply. I was thinking the classpath in .classpath file which is correct. As you said classpath entry is missing from manifest file. here is my manifest file. How do i update manifest file with classpath entry. Log4j Jar file is sitting in the folder c:\SampleJar\SampleJar

type manifest
Manifest-Version: 1.0
Main-Class: SampleJar
 
Sreenivasulu Naidu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
Iam able to edit the Manifest file with classpath entry and it works now. Thanks a lot for your quick reply and suggestion.
 
reply
    Bookmark Topic Watch Topic
  • New Topic