分享

求助,主类出问题

a3087661 发表于 2015-4-22 20:04:50 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 5 12618
zxy@zxy-virtual-machine:/usr/hadoop/hadoop-2.4.0$ jar tf WordCount.jar
META-INF/MANIFEST.MF
WordCount$IntSumReducer.class
WordCount$TokenizerMapper.class
WordCount.class
zxy@zxy-virtual-machine:/usr/hadoop/hadoop-2.4.0$ hadoop fs -ls /input
Found 1 items
-rw-r--r--   1 zxy supergroup        146 2015-04-22 19:32 /input/data.txt
zxy@zxy-virtual-machine:/usr/hadoop/hadoop-2.4.0$ hadoop jar WordCount.jar WordCount.class /input /output
Exception in thread "main" java.lang.ClassNotFoundException: WordCount.class
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        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:340)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:205)
zxy@zxy-virtual-machine:/usr/hadoop/hadoop-2.4.0$

已有(6)人评论

跳转到指定楼层
nettman 发表于 2015-4-22 20:15:11
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

a3087661 发表于 2015-4-22 20:18:39
nettman 发表于 2015-4-22 20:15
这个是系统自带的,还是自己写的。

看完之后,自己写的。但是没报错。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.LongWritable;
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;
import org.apache.hadoop.util.GenericOptionsParser;
public class WordCount {
  public static class TokenizerMapper
       extends Mapper<LongWritable, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text() ;
    public void map(LongWritable 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);//写入处理的中间结果<key,value>
      }
    }
  }


  public static class IntSumReducer
       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();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 2) {
      System.err.println("Usage: wordcount <in> <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);

  }
}


回复

使用道具 举报

nettman 发表于 2015-4-22 20:20:35
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

a3087661 发表于 2015-4-22 20:26:09
nettman 发表于 2015-4-22 20:20
hadoop jar WordCount.jar WordCount.class /input /output
去掉上面红字部分

成功了,多谢您的解答。
回复

使用道具 举报

a3087661 发表于 2015-4-22 20:51:03
本帖最后由 a3087661 于 2015-4-23 06:45 编辑
nettman 发表于 2015-4-22 20:20
hadoop jar WordCount.jar WordCount.class /input /output
去掉上面红字部分

哥,再麻烦你一下。问个问题。
7.当前日志采样格式为

  • a,b,c,d
  • b,b,f,e
  • a,a,c,f

[color=rgb(51, 102, 153) !important]复制代码



请用你最熟悉的语言编写一个mapreduce,并计算第四列每个元素出现的个数。

使用这个代码,其他WordCount部分不变,能解决么?
public void map(LongWritable key , Text value, Context context
                    ) throws IOException, InterruptedException {
        String []str=value.toString().split(",");
        word.set(str[3].toString());
        context.write(word, one);//写入处理的中间结果<key,value>

    }


点评

思路应该没有错,后面还需要reduce统计一下。祝你成功  发表于 2015-4-22 22:16
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条