Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception
To tackle the ClassNotFoundException
for org.apache.commons.logging.LogFactory
, add the Apache Commons Logging JAR to your project. Plug this into your Maven pom.xml
:
Or, if you're #TeamGradle, add this to build.gradle
:
This quick fix should help your application find the required logging classes like a treasure hunter finds gold!
Locating our JAR on the classpath
Ensure the commons-logging.jar
is present in your classpath, like making sure you haven't left your wallet at home:
- Eclipse users, navigate through
Project Properties
→Java Build Path
. - IntelliJ aficionados, go to
File
→Project Structure
→Libraries
.
Old school and not using an IDE or build tools like Maven or Gradle? Download commons-logging.jar
from the Apache website and sneak it into your application's lib
folder.
Exploring other cool logging frameworks
Fancy some SLF4J action instead? Replace commons-logging
with SLF4J's bridging module jcl-over-slf4j
:
This reroutes calls to admin's favourite, commons-logging
, to SLF4J, for advanced logging management. It's like taking a detour but ending up at a better destination!
Fine-tuning and compatibility checks
Ensure no typos have crept into the pom.xml
or build.gradle
. Recheck the groupIds and artifactIds for precision. You wouldn't mistype your own name, right?
While version
1.2 is stated here, different projects may go better with 1.1.1
or 1.1.2
. Always opt for the version that clicks with your project setup best.
Persisting issues and resolution
- Spot the exact name of the
LogFactory
class in the JAR; a decompiler plugin might be of immense help here. - Juggling multiple projects? Check for clashing versions of
commons-logging
on the classpath. - When you're rolling out your app, confirm the JAR is part of the deployment artifact (WAR, EAR, or a fat JAR).
Was this article helpful?