Fix java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
Codemia Knowledge Hub ·
This exception means the JVM could not find org.apache.commons.logging.LogFactory on the classpath: your code (or a library it uses) depends on Apache Commons Logging, but commons-logging.jar is not available at runtime. The fix is to add that JAR, usually as a Maven or Gradle dependency, and make sure every classloader that needs it can see it.
What ClassNotFoundException means
java.lang.ClassNotFoundException is a checked exception thrown when an application tries to load a class by its string name and no definition is found. Methods in the class loading mechanism such as Class.forName(), ClassLoader.findSystemClass() and ClassLoader.loadClass() throw it. It happens at runtime and indicates that the environment lacks the library or JAR that contains the class.
org.apache.commons.logging.LogFactory belongs to Apache Commons Logging, a lightweight bridge API over various logging implementations. Seeing this exception means the application is trying to use Commons Logging but the library is not in the build path or classpath.
Why the LogFactory class is missing
- Missing library: the most common cause.
commons-logging.jaris not on the project's classpath. - Incorrect dependency management: a misconfigured
pom.xmlorbuild.gradleleaves the dependency out. - Classloader conflicts: in applications with multiple class loaders, one loader may load the logging library without sharing it with the others.
Example that triggers the exception
This class uses Commons Logging:
Run it without commons-logging.jar on the classpath and the JVM throws ClassNotFoundException.
How to fix it
1. Add the Commons Logging library
Make sure commons-logging.jar is on the classpath. If you manage libraries by hand, download the JAR from the Apache Commons Logging website. With Maven, add this to pom.xml:
With Gradle, add this to build.gradle:
2. Check the dependency setup
If you use a dependency management tool, confirm the configuration is correct, the local repository is up to date, and proxy settings do not block access to the repositories.
3. Check the classpath in your build environment
For manually managed projects, confirm the JARs are actually included by your IDE settings or build scripts.
4. Resolve classloader issues
In applications with multiple class loaders or a complex loading hierarchy (common in J2EE containers like Tomcat), make sure commons-logging.jar is reachable across those boundaries. This may mean placing the JAR in a shared library directory such as CATALINA_HOME/lib for Tomcat.
| Issue | Description | Solution |
| Missing Library | Commons Logging JAR is not in classpath | Add commons-logging.jar to classpath |
| Dependency Management Errors | Misconfigured pom.xml or build.gradle | Correct and verify dependency management setup |
| Classloader Conflicts | Different class loaders cannot access the same library | Place JAR in shared classloader paths |
What Commons Logging does
Apache Commons Logging is an abstraction layer. It does not do the logging itself but delegates to an underlying framework such as Log4j, SLF4J or the built-in java.util.logging.
Many modern applications use SLF4J (Simple Logging Facade for Java) instead, because of its simpler architecture and wide support. If you migrate, make sure all logging calls are mapped correctly.
Related reading
- Getting java.lang.IllegalStateException Tried to lookup lag for unknown task 3_0 after upgrading Kafka Stream from 2.5.1 to 2.6.2
- Getting java.nio.file.AccessDeniedException on kafka on Windows
- Getting NoSuchMethodError javax.servlet.ServletContext.addServlet in Spring Boot while running a Spring MVC application
- Getting NullPointerException while connecting with ignite server node
- Getting random numbers in Java
- Getting Spring Application Context
- Getting Spring Boot color console logging working within Intellij?
- Getting the array length of a 2D array in Java
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.