Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If Hadoop reports NoClassDefFoundError with (wrong name: ...), first check the class’s package declaration, its path inside the JAR, and the fully qualified name in your hadoop jar command. That suffix usually indicates that the JVM found a class file whose embedded name does not match the name it was asked to load. If there is no wrong name suffix, investigate missing dependencies, YARN’s separate container classpaths, or an earlier class-initialization failure instead.

Start with the complete error

NoClassDefFoundError is a JVM linkage error: a class definition needed at runtime cannot be found, although the calling code was compiled with that class available. The exception alone does not prove that your application class is misspelled. The exact wording and the first underlying cause determine where to look. See Oracle’s definition of NoClassDefFoundError.

  • (wrong name: ...) appears: Prioritize the requested binary name versus the name embedded in the class file. Check package, JAR entry path, capitalization, and launch command.
  • A dependency name appears without wrong name: The class may not be on the classpath of the process that failed. Determine whether that process is the submitting client, the YARN ApplicationMaster, or a task container.
  • The error follows a failed static initializer: A class whose initialization already failed can produce a later NoClassDefFoundError. Read the earliest exception and first Caused by in the complete log rather than treating the later error as proof of a missing JAR.
  • NoSuchMethodError, NoSuchFieldError, or another linkage error appears after adding JARs: Suspect incompatible or duplicate library versions, not simply too few JARs.

A related ClassNotFoundException commonly indicates that a class loader could not locate a requested class. It can occur alongside a Hadoop launch or class-loading failure, but does not by itself identify whether the name, package, or distribution of the class is wrong.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix a binary-name mismatch

Java’s binary name includes the package. For example, this declaration:

package com.acme.jobs;

public class WordCount {
}

defines com.acme.jobs.WordCount, not simply WordCount. Its normal location in a JAR is:

com/acme/jobs/WordCount.class

The JAR’s filename does not determine the class name. A file called wordcount.jar can contain classes in any package. The source declaration, the compiled class’s internal name, its JAR path, and the name supplied to the launcher must agree.

Inspect the exact JAR you submit

Run these checks against the artifact named in your Hadoop command—not a similarly named JAR elsewhere:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
jar tf target/wordcount.jar | grep 'WordCount.class'

For the example above, expect:

com/acme/jobs/WordCount.class

Then inspect the compiled class’s declared binary name:

javap -verbose target/classes/com/acme/jobs/WordCount.class | grep this_class

You can also ask javap to resolve the class by its fully qualified name from the JAR:

javap -classpath target/wordcount.jar com.acme.jobs.WordCount

Compare the result with the source file’s package line and the JAR entry. For a closer look at the archive contents:

rm -rf /tmp/wordcount-check
mkdir -p /tmp/wordcount-check
unzip -q target/wordcount.jar -d /tmp/wordcount-check
find /tmp/wordcount-check -name '*.class' | sort

A useful source layout is src/main/java/com/acme/jobs/WordCount.java with package com.acme.jobs;. Correct the source or build configuration if the bytecode’s binary name and archive path disagree. Do not try to fix the mismatch by manually renaming only the .java or .class file: the bytecode carries its own class name.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capitalization matters. Package and class names are case-sensitive to the JVM; a mismatch that goes unnoticed on one development setup can fail on a case-sensitive cluster filesystem. Also check for duplicate copies of a class: an earlier JAR on the runtime classpath may be supplying old or differently packaged bytecode.

Use the fully qualified class name in the Hadoop command

For the example class, the unambiguous launch form is:

hadoop jar target/wordcount.jar com.acme.jobs.WordCount input output

These forms are wrong if the class declares package com.acme.jobs;:

hadoop jar target/wordcount.jar WordCount input output
hadoop jar target/wordcount.jar com.acme.WordCount input output

Some JARs specify a main class in their manifest, in which case hadoop jar target/wordcount.jar input output may be accepted. While diagnosing a class-name problem, supply the fully qualified main-class name explicitly so you can rule out reliance on the manifest. For a plain Java test, outside Hadoop, use:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
java -cp target/classes com.acme.jobs.WordCount

On a Unix-like system, a JAR and a directory of dependencies can be tested with:

java -cp 'target/wordcount.jar:target/lib/*' com.acme.jobs.WordCount

Windows uses a semicolon between classpath entries:

java -cp "targetwordcount.jar;targetlib*" com.acme.jobs.WordCount

A successful local Java test is useful, but it does not establish that YARN containers receive the same JARs.

Clean-build and verify the artifact

Stale build output and accidentally submitting an older copied JAR are common reasons a corrected package or class name appears not to help. Rebuild cleanly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mvn clean package

For Gradle, use:

./gradlew clean build

Then check the actual output and its contents:

ls -l target/*.jar
jar tf target/wordcount.jar | grep 'com/acme/jobs/WordCount.class'

Confirm that the path printed in the Hadoop submission command is the newly built JAR. After a genuine name or packaging fix, the wrong name error should disappear; execution may then proceed to argument parsing or job submission. A new, different error is a clue to follow, not a reason to keep renaming classes.

If the failure is a missing dependency, locate the failing process

In a Hadoop job, “the classpath” is not a single environment shared by every stage. The submitting client resolves and submits the job; the ApplicationMaster runs in a YARN container; map and reduce tasks run in other containers. A library visible to the client may not be localized to either kind of container. Conversely, a local launch can succeed while the distributed job fails.

Start with the client’s view:

hadoop classpath
printf '%sn' "$CLASSPATH"
printf '%sn' "$HADOOP_CLASSPATH"
printf '%sn' "$HADOOP_CONF_DIR"

For a YARN submission, inspect the distributed logs using the application ID. The following is the standard Hadoop 2/3 form, but vendor distributions, security settings, and command options can vary:

yarn logs -applicationId application_XXXXXXXXXXXX_YYYY

Search the logs for NoClassDefFoundError, ClassNotFoundException, wrong name, and Could not find or load main class. Identify whether the first failure is in the ApplicationMaster or a task container, then identify the missing class and the JAR that should provide it. That process is where the class must be visible.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For Hadoop YARN applications, Apache’s documentation stresses that classpath syntax and the resources localized to containers must be correct; see Writing YARN Applications. Do not assume that adding a JAR to the shell’s CLASSPATH automatically distributes it to every container.

Distribute application-only dependencies deliberately

Where supported by the job launcher and Hadoop version, -libjars is one way to make additional JARs available to a MapReduce job:

hadoop jar target/wordcount.jar 
  -libjars target/lib/dependency-a.jar,target/lib/dependency-b.jar 
  com.acme.jobs.WordCount input output

Its usefulness depends on how the launcher processes arguments and how the application parses them. Confirm that the option reaches Hadoop as intended, and distinguish dependencies needed by the client from those needed by the ApplicationMaster and tasks. Apache HBase documents both HADOOP_CLASSPATH and -libjars approaches for its MapReduce classes in its MapReduce guide; use the approach appropriate to the integration and cluster.

If your deployment uses a YARN framework archive, its configured archive path and application classpath must refer to the same localized archive and alias. Apache’s Hadoop 3.3.0 deployment guidance describes the relationship between mapreduce.application.framework.path and mapreduce.application.classpath. A Hadoop 2.10.2 example is available in its framework archive documentation. These are version-specific examples, not universal paths: match the archive alias, directory layout, and settings to your Hadoop release and distribution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A nested dependency JAR inside another JAR’s lib/ directory is not generally loadable just because it is nested there. The runtime classpath must include the dependency itself, or the build must produce an executable artifact with a layout and loader that can load its contents.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a dependency strategy without creating a conflict

Use the cluster’s Hadoop libraries when they are intended to supply the Hadoop APIs and runtime for the job; distribute application-specific libraries through the supported job mechanism. A thin application JAR is often the safer choice when the cluster provides compatible Hadoop libraries. A fat or “uber” JAR can help when required application dependencies are otherwise unavailable, but it can also package duplicate Hadoop classes, incompatible transitive dependencies, colliding resources, or broken service-provider metadata.

Hadoop’s compatibility guidance cautions against indiscriminately exposing Hadoop and third-party libraries, since changes to dependency visibility can cause application classpath conflicts. In particular, do not copy arbitrary JARs into $HADOOP_HOME/lib as a default fix: that alters a shared runtime and may affect other jobs.

Check dependency versions and duplicates before adding more libraries:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mvn dependency:tree -Dincludes=org.apache.hadoop
find "$HADOOP_HOME" -type f -name '*.jar' | sort

For Gradle:

./gradlew dependencies

Keep related Hadoop artifacts—such as hadoop-common, hadoop-hdfs-client, hadoop-mapreduce-client-core, and hadoop-yarn-*—aligned with the target distribution unless its vendor documents a different arrangement. An application built against a different set of libraries may find a class but fail when a method or field is incompatible. If a new NoSuchMethodError or NoSuchFieldError appears after adding a JAR, remove or align conflicting versions rather than adding still more copies.

Selective shading and relocation can isolate some third-party dependencies in an uber JAR. The Maven Shade Plugin relocation example explains this technique. Relocation changes package names, however, and can require changes to configuration strings, reflective class lookups, service files, or serialized class names. Do not automatically relocate Hadoop APIs or bundle a second Hadoop runtime unless the deployment model explicitly requires it.

Check integrations when the missing class is not yours

If the failing name belongs to an integration, trace that library’s dependencies and distribution rather than changing your main-class name. Examples include HBase MapReduce classes absent from task classpaths, Hive auxiliary JARs missing from the execution environment, or Spark-on-YARN archives that do not include an application dependency. For Hadoop S3A, the S3A troubleshooting guide notes that hadoop-aws needs a compatible AWS SDK bundle and that its version must match the Hadoop libraries it works with. These examples are diagnostic branches, not a presumption that an integration is the cause of every error.

Quick decision table

Symptom First thing to check
(wrong name: ...) Source package, bytecode name, JAR entry path, launch name, and capitalization.
Missing org.apache.hadoop... class in YARN ApplicationMaster or task-container logs and the Hadoop/MapReduce classpath for that process.
Missing third-party class Whether its runtime dependency is included and distributed to every process that needs it.
Works locally but fails on YARN Localized resources and the actual container logs; local classpath success is not proof of container visibility.
NoSuchMethodError after adding JARs Duplicate or incompatible dependency versions, especially Hadoop and integration libraries.
Class appears in the JAR but still fails Whether that exact JAR is submitted, loaded by the failing classloader, and present in the container; also check duplicate classes and stale bytecode.
Only one node or environment fails Compare Hadoop configuration and JAR inventories; distributions and node installations may differ.

Final checks before changing cluster configuration

  1. Save the complete stack trace and identify the earliest cause.
  2. Check whether the message contains (wrong name: ...).
  3. For a name mismatch, compare the source package, javap binary name, JAR entry, and fully qualified launch name.
  4. Clean-build, then inspect the exact artifact path and contents used for submission.
  5. For a missing dependency, identify whether the client, ApplicationMaster, or task container failed and inspect that process’s logs and resources.
  6. Check for duplicate or version-skewed libraries before adding dependencies.
  7. Change job-scoped classpath or distribution settings where practical; avoid broad shared-runtime changes unless the cluster administrator and distribution documentation call for them.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.