By user188102


2009-10-11 20:33:56 8 Comments

i am executing simple Dependency Injection program of spring & getting this exception. I have already included common-logging1.1.1.jar and spring.jar file. Could you please help to out?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:119)
    at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:55)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
    at com.client.StoryReader.main(StoryReader.java:15)
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)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 6 more

25 comments

@paul 2019-03-25 08:46:18

In my case I was testing a Tomcat app in eclipse and got this error. I solved it by checking the .classpath file and corrected this entry:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

The attribute org.eclipse.jst.component.dependency had been missing.

@Yuliem Alavez 2018-06-12 21:09:09

I have the same problem in eclipse IDE, my solution was: Right click in My project > Properties

enter image description here

Click in Maven and write: jar in the Active Maven Project

enter image description here

Finally, Apply and Close

@Anmol Gupta 2018-04-08 13:17:44

I was getting the same error while the jar was present. No solution worked. What worked was deleting the jar from the file system (from .m2 directory) and then cleaning the maven project.

@歌永_ 2017-03-14 20:59:49

I got the same trouble than you. Finally I checked the version of apache possessing the class. I found that the version 1.0.4 has the class.

Try to use the version 1.0.4 instead of 1.1.X or 1.2.X

My dependencies :

    <dependencies>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-client-java</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
    </dependencies>

My Java Code

J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia");
J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory","HeapMemoryUsage");
req.setPath("used");
J4pReadResponse resp = j4pClient.execute(req);
System.out.println(resp.getValue());

My Result :

130489168

Double check also that your maven dependencies are well imported.

@Voy 2016-06-29 20:29:42

If you're running this on Android then note that apparently java.beans package is not complete on Android. To attempt to fix it on Android try the following:

  1. Download android-java-air-bridge.jar (currently the download button is on the bottom of the page or direct link here)
  2. Copy the downloaded jar to your [APPROOT]/app/libs directory (or link the jar in any other way)
  3. Change the import *** statements to that of air-bridge. Eg import javadz.beanutils.BeanUtils instead of import org.apache.commons.beanutils.BeanUtils;
  4. Clean and rebuild the project

source 1, source 2

I apologise as I realise this is not exactly answering the question, though this SO page comes up a lot when searching for android-generated NoClassDefFoundError: Failed resolution of: beanUtils errors.

@APal 2016-06-08 08:03:31

Adding commons-logging.jar or commons-logging-1.1.jar will solve this...

@Patrick Brielmayer 2016-04-26 15:33:16

Setting the scope to compile did it for me

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

@venugopal 2017-06-30 20:38:11

Solved my situation. When running Mockito test cases, I got this error and having this dependency in pom.xml solved.

@user1244663 2015-10-20 07:54:59

try adding this dependency org.apache.commons commons-exec 1.3

@devaaron 2015-07-23 21:25:18

Two options (at least):

  1. Add the commons-logging jar to your file by copying it into a local folder.

Note: linking the jar can lead to problems with the server and maybe the reason why it's added to the build path but not solving the server startup problem.

So don't point the jar to an external folder.

OR...

  1. If you really don't want to add it locally because you're sharing the jar between projects, then...

If you're using a tc server instance, then you need to add the jar as an external jar to the server instance run configurations.

go to run as, run configurations..., {your tc server instance}, and then the Class Path tab.

Then add the commons-logging jar.

@Tush 2013-06-25 13:27:49

Issue solved by adding commons-logging.jar

Imp files are ,

antlr-runtime-3.0.1

org.springframework.aop-3.1.0.M2

org.springframework.asm-3.1.0.M2

org.springframework.aspects-3.1.0.M2

org.springframework.beans-3.1.0.M2

org.springframework.context.support-3.1.0.M2

org.springframework.context-3.1.0.M2

org.springframework.core-3.1.0.M2

org.springframework.expression-3.1.0.M2

commons-logging-1.1.1

@Jesper 2009-10-11 20:51:21

I have already included common-logging1.1.1.jar and ...

Are you sure you spelled the name of the JAR file exactly right? I think it should probably be commons-logging-1.1.1.jar (note the extra - in the name). Also check if the directory name is correct.

NoClassDefFoundError always means that a class cannot be found, so most likely your class path is not correct.

@skaffman 2009-10-11 21:12:39

NoClassDefFoundError can also be caused by other corner cases, like when class initializers fail in obscure circumstances.

@Jesper 2009-10-11 21:14:17

Yes, but 99.9% of the time it's caused by class path errors.

@Kolibri 2009-10-11 22:04:17

Furthermore, if he gets a NoClassDefFoundError because the class instantiation failed, then he should have gotten a ExceptionInInitializerError exception first (unless of course it was caught silently).

@Glenn Lawrence 2015-03-16 00:21:34

And don't forget the "s" commons-logging-1.1.1.jar

@Jesper 2015-03-16 07:39:19

@GlennLawrence Thanks, fixed the name.

@The Third 2014-10-06 20:46:35

Hey I was following the tutorial on tutorialpoint.com. Add after you complete Step 2 - Install Apache Common Logging API: You must import external jar libraries to the project from the files downloaded at this step. For me the file name was "commons-logging-1.1.1".

@Sibichakravarthy Gunasekaran 2014-09-16 12:00:53

Check whether the jars are imported properly. I imported them using build path. But it didn't recognise the jar in WAR/lib folder. Later, I copied the same jar to war/lib folder. It works fine now. You can refresh / clean your project.

@Bob V. 2014-08-14 19:01:15

If all else fails, as it had for me, try putting the commons-logging-x.y.z.jar in your Tomcat lib directory. It solved the problem! BTW, I am using Tomcat 6.

@Bob V. 2014-08-14 19:22:12

name thing? what are you talking about?

@Sachin 2014-07-28 07:38:42

Solution is to Add common-logging.x.x jar file

@Paramesh Korrakuti 2014-07-17 15:38:28

commons-logging-1.1.1.jar or jcl-over-slf4j-1.7.6.jar al

If you are using maven, use the below code.

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

@Italo Borssatto 2017-05-05 19:00:17

Including "jcl-over-slf4j" was the only solution that works for me. I already had the commons-logging in my dependencies.

@Carlos Nantes 2018-09-19 18:24:07

I'm using spring-boot version 2.0.1.RELEASE with maven. This was the only solution that worked for me too.

@Krishnarjun 2013-07-18 07:14:58

Hello friends if your getting any not class found exception in hibernate code it is the problem of jar files.here mainly two problems
1.I mean to say your working old version of hibernate may be 3.2 bellow.So if u try above 3.6 it will works fine

2.first checkes database connection.if it database working properly their was a mistake in ur program or jar file.

please check these two prioblems if it also not working you tried to IDE . I am using netbeanside 6.9 version.here hibernate working fine.you dont get any error from class not founnd exception..

I hope this one helps more

@asuka 2013-07-03 10:49:40

If you're using maven for managing dependencies, add the following line in your pom.xml:

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

@stacky 2013-04-27 11:42:44

I had the same problem, and solved it by just adding the commons-logging.jar to the class path.

@sonida 2013-04-23 07:37:56

You just download commons-logging-1.1.2.jar and then copy this file in to libs

finally, it works.

@rash 2012-07-30 09:09:08

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

use this url to download jar files and include them in your class path, issue will be solved

@Manikandan 2011-07-18 09:28:48

I have also faced the same issues, to fix, download the jar files from the below url

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

and copy to your lib folder, will resolve your issue.

@Deen John 2016-09-08 20:22:47

this doesn't work for me ,even after adding above mentioned commons jar in classpath

@Wesos de Queso 2017-07-30 16:53:52

Neither for me. These libs are broken. It's so frustating.

@brianegge 2009-12-24 03:14:23

I generally assign the classpath to a variable and then verify it. I've written a small ruby script which I include in a my startup scripts which validates the classpath before launching java. Validating the classpath before the JVM starts has saved me lots of time troubleshooting these types of problems.

@Neovibrant 2012-09-17 00:21:50

You should consider using tools like Maven instead.

@dhammikas 2009-10-14 08:30:55

Just check whether the commons-logging.jar has been added to your libs and the classpath.. I had the same issue and that was because of this. dhammikas-

@emills 2009-10-11 20:49:54

Try doing a complete clean of the target/deployment directory for the app to get rid of any stale library jars. Make a fresh build and check that commons-logging.jar is actually being placed in the correct lib folder. It might not be included when you are building the library for the application.

Related Questions

Sponsored Content

1 Answered Questions

Spring java.lang.NoClassDefFoundError

1 Answered Questions

[SOLVED] Getting error in executing OWL API

  • 2015-05-26 13:04:43
  • kravi
  • 3200 View
  • 2 Score
  • 1 Answer
  • Tags:   java owl

1 Answered Questions

1 Answered Questions

[SOLVED] "Getting started" issue with JOSS JavaSWIFT

1 Answered Questions

[SOLVED] Upload an Object Using the AWS SDK for Java

1 Answered Questions

[SOLVED] why base64 class is not found when code compiles ok and classpath is set

  • 2014-09-22 09:11:37
  • Tom
  • 2137 View
  • 1 Score
  • 1 Answer
  • Tags:   java

2 Answered Questions

2 Answered Questions

Sponsored Content