在windows上用eclipse远程运行hadoop上的wordcount程序出现的问题,求解决

WordCount源代码如下:

 
  
  1. package org.apache.hadoop.examples;

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

  4. import org.apache.hadoop.conf.Configuration;
  5. import org.apache.hadoop.fs.Path;
  6. import org.apache.hadoop.io.IntWritable;
  7. import org.apache.hadoop.io.Text;
  8. import org.apache.hadoop.mapreduce.Job;
  9. import org.apache.hadoop.mapreduce.Mapper;
  10. import org.apache.hadoop.mapreduce.Reducer;
  11. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  12. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  13. import org.apache.hadoop.util.GenericOptionsParser;

  14. public class WordCount {

  15.   public static class TokenizerMapper 
  16.        extends Mapper{
  17.     
  18.     private final static IntWritable one = new IntWritable(1);
  19.     private Text word = new Text();
  20.       
  21.     public void map(Object key, Text value, Context context
  22.                     ) throws IOException, InterruptedException {
  23.       StringTokenizer itr = new StringTokenizer(value.toString());
  24.       while (itr.hasMoreTokens()) {
  25.         word.set(itr.nextToken());
  26.         context.write(word, one);
  27.       }
  28.     }
  29.   }
  30.   
  31.   public static class IntSumReducer 
  32.        extends Reducer {
  33.     private IntWritable result = new IntWritable();

  34.     public void reduce(Text key, Iterable values, 
  35.                        Context context
  36.                        ) throws IOException, InterruptedException {
  37.       int sum = 0;
  38.       for (IntWritable val : values) {
  39.         sum += val.get();
  40.       }
  41.       result.set(sum);
  42.       context.write(key, result);
  43.     }
  44.   }

  45.   public static void main(String[] args) throws Exception {
  46.     Configuration conf = new Configuration();
  47.     conf.set("mapred.job.tracker", "192.168.80.100:9001");
  48.     String[] ars=new String[]{"in","newout"};
  49.     String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs();
  50.     if (otherArgs.length != 2) {
  51.       System.err.println("Usage: wordcount ");
  52.       System.exit(2);
  53.     }
  54.     Job job = new Job(conf, "wordcount");
  55.     job.setJarByClass(WordCount.class);
  56.     job.setMapperClass(TokenizerMapper.class);
  57.     job.setCombinerClass(IntSumReducer.class);
  58.     job.setReducerClass(IntSumReducer.class);
  59.     job.setOutputKeyClass(Text.class);
  60.     job.setOutputValueClass(IntWritable.class);
  61.     FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  62.     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  63.     System.exit(job.waitForCompletion(true) ? 0 : 1);
  64.   }
  65. }

运行run on hadoop后报错内容如下:

13/12/22 18:49:11 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/12/22 18:49:11 INFO mapred.JobClient: Cleaning up the staging area hdfs://hadoop001:9000/usr/local/hadoop/tmp/mapred/staging/root/.staging/job_201312221708_0002
13/12/22 18:49:11 ERROR security.UserGroupInformation: PriviledgedActionException as:root cause:org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/E:/hadoop/eclipse/workspace/WordCount/in
Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/E:/hadoop/eclipse/workspace/WordCount/in
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus(FileInputFormat.java:235)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.getSplits(FileInputFormat.java:252)
at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:1024)
at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:1041)
at org.apache.hadoop.mapred.JobClient.access$700(JobClient.java:179)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:959)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:912)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Unknown Source)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1149)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:912)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
at org.apache.hadoop.examples.WordCount.main(WordCount.java:69)


解决办法:

捣鼓了一整天终于找到解决的办法了,原来是我之前参考的《hadoop集群第七期》http://www.cnblogs.com/xia520pi/archive/2012/05/20/2510723.html

在windows上用eclipse远程运行hadoop上的wordcount程序出现的问题,求解决_第1张图片

注意第52和53行,然后运行的时候老是出错,如前面所述的错误,然后百度了半天才知道是hadoop-core-1.1.2.jar这个包的问题,org.apache.hadoop.fs里面的一个类名为

FileUtl.class中的一个方法checkReturnValue搞的鬼,这个方法是检查Windows下文件权限问题,在Linux下可以正常运行,不存在这样的问题。

因此将此方法注释掉就OK了,但是为了方便,还是从网上重新找了hadoop-core-1.1.2.jar下载下来,将原先的hadoop-core-1.1.2.jar替换掉,然后再在eclipse里面运行

wordcount.java就成功了。

纪念一下:

在windows上用eclipse远程运行hadoop上的wordcount程序出现的问题,求解决_第2张图片

总结:网上别人写的东西有好有坏,得学会亲自动手解决。这里我留下代码修改后的hadoop-core-1.1.2.jar的下载地址,有需要的童鞋可以下载替换原先的jar包试试,嘿嘿!

http://download.csdn.net/detail/qq_417174491/6755193

你可能感兴趣的:(云计算,错误笔记)