Java
Spark
NoClassDefFoundError
Logging
Troubleshooting

java.lang.NoClassDefFoundError org/apache/spark/Logging

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

java.lang.NoClassDefFoundError: org/apache/spark/Logging usually means your code or one of your dependencies was compiled against an older Spark API that is not present in the Spark runtime you are actually using. This is a classpath and version-alignment problem, not a logging configuration problem.

Why This Error Happens

Older Spark code exposed org.apache.spark.Logging. Modern Spark code uses internal logging traits such as org.apache.spark.internal.Logging instead.

That means a library compiled for one Spark generation may reference a class that no longer exists in the runtime jars for another generation. When the JVM tries to load that missing class, you get NoClassDefFoundError.

A common scenario looks like this:

  • application code is built against one Spark version
  • cluster or local runtime provides a different Spark version
  • a transitive dependency expects an older Spark internal class

The word “Logging” in the class name is misleading here. The actual issue is binary incompatibility.

Check Build and Runtime Spark Versions

Start by verifying the Spark version in both places:

  • your build file
  • the runtime environment or cluster
  • any fat jar or assembly output

For Maven, that usually means inspecting the Spark dependency coordinates.

xml
1<dependency>
2  <groupId>org.apache.spark</groupId>
3  <artifactId>spark-core_2.12</artifactId>
4  <version>3.5.1</version>
5  <scope>provided</scope>
6</dependency>

If your application is submitted to a cluster running a different Spark version, rebuild against the exact version the cluster provides.

Recompile Code That Uses Old Internal APIs

If your own Scala or Java code directly references org.apache.spark.Logging, the right fix is to update that code rather than trying to force old Spark jars into a new runtime.

scala
1import org.apache.spark.internal.Logging
2
3object JobRunner extends Logging {
4  def main(args: Array[String]): Unit = {
5    logInfo("Starting job")
6  }
7}

The exact replacement depends on your Spark version, but the larger rule is simple: avoid depending on Spark internal classes unless you must, because those APIs are more likely to move.

Watch for Shaded or Bundled Jar Problems

Even when your direct dependency looks correct, an old third-party jar can still pull in assumptions from another Spark release. That is common with internal utilities, old connectors, or reused company libraries.

Check your dependency tree and assembly output for mismatched Spark artifacts. A single stale jar can cause the runtime to look for classes that are no longer present.

For Maven, mvn dependency:tree is often enough to spot the mismatch. For SBT, sbt dependencyTree serves the same purpose.

Do Not Fix It by Copying Random Spark Jars

A tempting but risky response is to drop another Spark jar onto the classpath until the missing class appears. That usually creates deeper incompatibilities.

Spark dependencies are version-coupled. Mixing arbitrary jars can replace one NoClassDefFoundError with method-signature errors, serializer problems, or executor failures later in the job.

The robust fix is version alignment, not classpath pile-up.

Common Pitfalls

  • Treating the error as a Log4j or SLF4J configuration issue when it is really a missing Spark class.
  • Building against one Spark version and running against another.
  • Depending directly on Spark internal APIs that are not stable across releases.
  • Ignoring transitive dependencies that bring in old Spark assumptions.
  • Trying to patch the problem by adding random Spark jars instead of aligning versions properly.

Summary

  • 'org/apache/spark/Logging errors usually mean a Spark version mismatch or stale dependency.'
  • The problem is classpath compatibility, not logger setup.
  • Rebuild against the same Spark version your runtime uses.
  • Update code that depends on old internal Spark logging classes.
  • Prefer version alignment over ad hoc jar fixes.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.