简体   繁体   English

Hadoop:java.lang.ClassNotFoundException:map-reduce

[英]Hadoop: java.lang.ClassNotFoundException:map-reduce

Hi I'm using eclipse to export the jar file of map reduce program.When i try to run the jar file using the command您好我正在使用eclipse导出map reduce程序的jar文件。当我尝试使用命令运行jar文件时

hadoop jar WordCountdemo.jar /Demo2/WordCount.txt /mroutput7utput7

I m getting error :我收到错误:

Exception in thread "main" java.lang.ClassNotFoundException: /Demo2/WordCount/txt
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:316)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:236)

My Program looks like below:我的程序如下所示:

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCountdemo {
    public static class Tmaper extends Mapper<Object, Text, Text, IntWritable>{
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        public void map(Object key, Text value, Context context
                ) throws IOException, InterruptedException{
            StringTokenizer itr = new StringTokenizer(value.toString());
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                context.write(word, one);
              }
        }
        
    }
    public static class Treducer extends Reducer<Text,IntWritable,Text,IntWritable>{
        private IntWritable result = new IntWritable();
        public void reduce(Text key, Iterable<IntWritable> values,
                Context context
                ) throws IOException, InterruptedException {
                int sum = 0;
                for (IntWritable val : values) {
                 sum += val.get();
                }
                result.set(sum);
                context.write(key, result);
                }
    }
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "word count");
        job.setJarByClass(WordCountdemo.class);
        job.setMapperClass(Tmaper.class);
        //job.setCombinerClass(Treducer.class);
        job.setReducerClass(Treducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        
        System.exit(job.waitForCompletion(true) ? 0 : 1);
      }
}

I'm not able to figure out what or where is the problem The code is taken from Hadoop我无法弄清楚问题出在哪里或出在哪里代码取自Hadoop

你错过了一个论点 - 类。

hadoop jar WordCountdemo.jar WordCountdemo /Demo2/WordCount.txt /mroutput7utput7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM