I am new to Spring framework. I checked the following answer regarding the similar problem as i have :Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception But,i have tried all the solutions mentioned in that link,None worked.So,i request not to close this post/mark duplicate.
I have been using the the JavaBrains Spring youtube lectures and running the same code as mentioned in the below lecture-4 link
Below is the main class as mentioned in above youtube lecture :
package org.learningSpring;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DrawingApp {
Log logger = LogFactory.getLog(DrawingApp.class);
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("org/learningSpring/Spring.xml");
Triangle triangle=(Triangle) context.getBean("triangle");
triangle.draw();
((ClassPathXmlApplicationContext) context).close();
}
}
Rest of the code is same as in the link :YoutubeLinkForCode
I am not using Maven for this & added all Jars manually.
Jars used in project :
- spring-framework-4.3.2.RELEASE-dist
- commons-logging-1.2 - downloaded from genuine resource Website from where i downloaded the jar
Below is the stack trace from exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:160)
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:224)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:88)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:58)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.deen.DrawingApp.main(DrawingApp.java:14)
I debug and found that the code throws exception in AbstractApplicationContext.class at below line:
public AbstractApplicationContext() {
this.logger = LogFactory.getLog(super.getClass()); //here
I made sure if there is LogFactory.class in commons-logging-1.2 jars and whether this class contains getLog method.
Below is my .classpath file.This contains the commons jar :
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Spring"/>
<classpathentry kind="lib" path="D:/Software/JAR/commons-logging-1.2-bin (2)/commons-logging-1.2/commons-logging-1.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
I read some answers on stackoverflow regarding this error and all they say is to add commons jar which i already added.
I have spent whole day trying to solve this error & feeling demoralised.I would be very much thankful if someone could help me to resolve this error.If you need any more detail then please let me know.