ClassNotFoundException: org.apache.commons.logging.LogFactory

Starting a web application, but hits the following error messages :

...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
...

1. Normal Case

1.1 Obviously, the Apache Commons logging is missing – commons-logging-xxx.jar. To fix it, get it from Maven central repository.

pom.xml

   <dependency>
	  <groupId>commons-logging</groupId>
	  <artifactId>commons-logging</artifactId>
	  <version>1.2</version>
   </dependency>

2. Spring Case

2.1 For Spring application, developers always excluded the commons-logging, but forget to include another logging framework. For example

pom.xml

   <dependency>
	  <groupId>org.springframework</groupId>
	  <artifactId>spring-webmvc</artifactId>
	  <version>${spring.version}</version>
	  <exclusions>
	      <exclusion>
		  <groupId>commons-logging</groupId>
		  <artifactId>commons-logging</artifactId>
	      </exclusion>
	  </exclusions>
   </dependency>

The above declaration will cause this classNotFoundException: org.apache.commons.logging.LogFactory also.

2.2 To fix it, declares another logging framework, often, this is SLF4j and redirect the Spring’s logging via a bridge.

pom.xml

   <dependency>
	  <groupId>org.springframework</groupId>
	  <artifactId>spring-webmvc</artifactId>
	  <version>${spring.version}</version>
	  <exclusions>
	      <exclusion>
		  <groupId>commons-logging</groupId>
		  <artifactId>commons-logging</artifactId>
	      </exclusion>
	  </exclusions>
   </dependency>

   <!-- bridge jck to slf4j -->
   <dependency>
	  <groupId>org.slf4j</groupId>
	  <artifactId>jcl-over-slf4j</artifactId>
	  <version>${jcl.slf4j.version}</version>
   </dependency>

   <dependency>
	  <groupId>ch.qos.logback</groupId>
	  <artifactId>logback-classic</artifactId>
	  <version>${logback.version}</version>
   </dependency>

References

  1. Apache Commons Logging
  2. Spring MVC + Logback SLF4j example

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Jason Rembert
Guest
Jason Rembert

Hello,

you can download the JAR with dependencies without installing Maven on: http://jar-download.com/

Andrea
Guest
Andrea

Great!!!!!

Thenmozhi
Guest
Thenmozhi

Hi…I am new to eclipse.I dont know how to add esper libraries with eclipse.But i copied a program from net and tried running it.I got noclass def error.So i downloaded logging jar file and added.Then also i am getting same error.Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at com.espertech.esper.client.Configuration.(Configuration.java:39)
at com.espertech.example.main(example.java:53)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
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)
… 2 more
This is the error i got.Could you please help me with a simple codding.I am a beginner.so please give it as concise as possible.

mahalakshmi
Guest
mahalakshmi
Hi MKyong, i am new to spring project,please kindly help me to resolve this error actually in project we are using sts and to do indexing we are using solr. Indexing is running fine at the time of spring 3.2.3 version after updating in to spring 3.2.4 version indexing is not working and i am getting below error ERROR context.ContextLoader: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.scheduling.quartz.SchedulerFactoryBean#1’ defined in ServletContext resource [/WEB-INF/classes/application-context.xml]: Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: The job (DEFAULT.productIndexJobDetail) referenced by the trigger does not exist. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)… Read more »
susi
Guest
susi

Hi sir!
Am new to Spring,please kindly help me to get rid of this ERROR!
when ever i try to run a spring project am getting the following errors:
Exception in thread “main” org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:158)
at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:89)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.byteslounge.spring.tx.Main.main(Main.java:16)
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
… 10 more
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
… 11 more

please give me a solution for this ERROR.

thanks in advance!

Alvaro
Guest
Alvaro

Thank you! Helped me a lot!

Bhawna
Guest
Bhawna

Thanks a lot :) it worked for me now :)

srikanth
Guest
srikanth

Thank you very much mkyong..i l u…

Osolya
Guest
Osolya

you have saved me!

Thank you very much!

Steff
Guest
Steff

you are welcome, Pwale

lakshmi
Guest
lakshmi
I am working on ejb project in netbeans using jboss server.when i am trying to send connection request to the router i am getting the following error.The error is shown at the line HttpClient client = new HttpClient(); i placed commons-httpclient-3.1.jar,commons-logging-1.1.jar,commons-codec.jar in my project. 12:43:48,854 ERROR [LogInterceptor] Unexpected Error in method: public abstract void org.openacs.HostsLocal.RequestConnection(long) throws java.lang.Exception java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.httpclient.HttpClient.(HttpClient.java:66) at org.openacs.HostsBean.RequestConnectionHttp(HostsBean.java:251) at org.openacs.HostsBean.RequestConnection(HostsBean.java:290) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.invocation.Invocation.performCall(Invocation.java:359) at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityConta iner.java:1187) at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRel ationInterceptor.java:87) at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntityS ynchronizationInterceptor.java:338) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo ke(CachedConnectionInterceptor.java:158) at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentr anceInterceptor.java:126) at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstance Interceptor.java:278) at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep tor.java:104) at… Read more »
shikha
Guest
shikha

hi sir,
I am working on a project in IBM WorkLight, Following Error occured Plz Help me
com.worklight.studio.plugin.classpath.server container(unbounded)

Steff
Guest
Steff

add following jars
1. commons-logging 1.x
2.log4j 1.x

Milind
Guest
Milind

Thanks alot. Its really helpful

Rajasekhar
Guest
Rajasekhar

Thanks…