NoClassDefFoundError or ClassNotFoundException

In this post we will discuss about most frequent error messages NoClassDefFoundError or ClassNotFoundException in hadoop mapreduce jobs execution and possible solutions for them.

Error Scenario:

java.lang.ClassNotFoundException or java.lang.NoClassDefFoundError
Error starting MRAppMaster & Container exited with a non-zero exit code 1

When we encounter a situation of NoClassDefFoundError or ClassNotFoundException even though we have required jar files added to our build path in eclipse, then we have a short cut to resolve this error message at run time.

Generally in this situation, when we have required jar files added to build path in eclipse, then we will not receive any compile error and when we run the same program from eclipse itself then also we will not face any issue.

But this type of exceptions will occur when we create jar file from eclipse and run it from command line. If we are running it with java command and there is no -classpath specified then we can give the jar file containing our required classes in -classpath argument as shown below.

But when we are already running a program from a jar file then we can’t pass the second jar file as argument to -classpath argument. Below is a scenario where we submit a mapreduce program from a jar file using hadoop command. In this case we can’t pass -classpath argument to specify our required jar file.

In this case, if JVM can’t find required class definitions at run time in test.jar file we will get below types of error messages. These below error messages were occurred when hadoop did not find class definitions for JSONObject and JSONException classes when we are using these two classes in our import statements as shown below in program in post Mapreduce multiple outputs.

Below are three different types of error messages.