windows下的hadoop-eclipse-plugin-2.6.0.jar配置問題

一.簡介java

   Windows下的 Eclipse上調試Hadoop2代碼,因此咱們在windows下的Eclipse配置hadoop-eclipse-plugin-2.6.0.jar插件,並在運行Hadoop代碼時出現了一系列的問題,搞了好幾天終於能運行起代碼。接下來咱們來看看問題並怎麼解決,提供給跟我一樣遇到的問題做爲參考。apache

Hadoop2的WordCount.java統計代碼以下:windows

 

package org.apache.hadoop.examples;

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 WordCount {

  public static class TokenizerMapper
       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 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();
    Job job = Job.getInstance(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(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}


問題一.An internal error occurred during: "Map/Reducelocation status updater".java.lang.NullPointerExceptionapp

   咱們hadoop-eclipse-plugin-2.6.0.jar放到Eclipse的plugins目錄下,咱們的Eclipse目錄是F:\tool\eclipse-jee-juno-SR2\eclipse-jee-juno-SR2\plugins,重啓一下Eclipse,而後,打開Window-->Preferens,能夠看到Hadoop Map/Reduc選項,而後點擊出現了An internal error occurredduring: "Map/Reduce location status updater".java.lang.NullPointerException,如圖所示:eclipse

   

  解決:oop

   咱們發現剛配置部署的Hadoop2還沒建立輸入和輸出目錄,先在hdfs上建個文件夾 。spa

   #bin/hdfs dfs -mkdir –p /user/root/input插件

   #bin/hdfs dfs -mkdir -p  /user/root/output調試

 咱們在Eclipse的DFS Locations目錄下看到咱們這兩個目錄,如圖所示:code

  

相關文章
相關標籤/搜索