在运行时找不到类定义(java.lang.noclassdeffounderror:matrixadd$map)

mbzjlibv  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(241)

我正在尝试在hadoop中执行矩阵加法。我的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在同一文件夹中形成。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题