Tag Archives: Hadoop running jar package error

[Solved] Hadoop running jar package error: xception in thread “main” java.lang.ClassNotFoundException: Filter

Execute Commands: [root@hadoop102 mapreduce]# hadoop jar mapreduce2_maven.jar Filter

Error Messages:

Exception in thread "main" java.lang.ClassNotFoundException: Filter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:311)
at org.apache.hadoop.util.RunJar.main(RunJar.java:232)

Solution: change hadoop jar mapreduce2_maven.jar Filter to hadoop jar mapreduce2_maven.jar exper.
Reason: class path problem

[Solved] Hadoop running jar package error: java.lang.exception: java.lang.arrayindexoutofboundsexception: 1

Error Messages:
java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: 1
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:492)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:552)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at exper.Filter$Map.map(Filter.java:25)
at exper.Filter$Map.map(Filter.java:19)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:799)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:347)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:271)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Reason for error: The source code sets the data separator as space, while the code separator in the dataset is tab tab
Modify the red marked statement.

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String line = value.toString();
    System.out.println(line);
    String arr[] = line.split("\t");
    newKey.set(arr[1]);
    context.write(newKey, NullWritable.get());
    System.out.println(newKey);
}

Then run the jar file on Linux:
enter the command under the folder where the jar package is stored:
Hadoop jar mapreducedemo-1.0-snapshot.jar exp.filter/mymapreduce2/in/buyer_Myfavorite1/user/root/mymapreduce2/out
runs successfully!