在运行时没有找到类定义(java.lang.NoClassDefFoundError:MatrixAdd $ Map)

时间:2016-03-11 04:14:47

标签: java hadoop runtime-error

我正在尝试在Hadoop中执行Matrix Addition。我的MatrixAdd.java类已成功编译,我成功创建了一个jar。但是我一直在运行时遇到错误,说java.lang.NoClassDefFoundError:MatrixAdd $ Map,其中我可以清楚地看到MatrixAsd $ Map.class和MatrixAdd $ Reduce.class已经形成在同一个文件夹中。

import java.io.IOException;
import java.util.*;      
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class MatrixAdd {

 public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable();
    private Text word = new Text();

    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
    int keys=Integer.parseInt(tokenizer.nextToken());
    int column=0;
        while (tokenizer.hasMoreTokens()) {
        String val=keys+"\t"+column;
        column++;
            word.set(val);
            context.write(word, new IntWritable(Integer.parseInt(tokenizer.nextToken())));
        }
    }
 } 

 public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
      throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.get();
        }
        context.write(key, new IntWritable(sum));
    }
 }

[This is the error message given. ma1 is the jar file created][1]

 public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();

        Job job = new Job(conf, "wordcount");

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(Map.class);
    job.setReducerClass(Reduce.class);

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.waitForCompletion(true);
 }
}


Exception in thread "main" java.lang.NoClassDefFoundError: MatrixAdd$Map
    at MatrixAdd.main(MatrixAdd.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: MatrixAdd$Map
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 7 more

编译后,MatrixAdd.class MatrixAdd $ Map.class和MatrixAdd $ Reduce.class与MatrixAdd.java和MatrixAdd.class在同一文件夹中形成。

0 个答案:

没有答案