Tuesday, May 1, 2012

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:145)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:84)
        at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
        at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:58)
        at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
        at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
        at TestHelloSpring.main(TestHelloSpring.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

If you get above error, probably your application is not able to find commons-logging.jar in classpath.

Download the latest version of JAR file from below URL and add it to classpath of your applications classpath

http://commons.apache.org/logging/download_logging.cgi

To know more about Apache Commons Logging, click here