hadoop2.8.1在eclipse 运行can not find winutils.exe文件附下载地址

来源:互联网 发布:apache bench 编辑:程序博客网 时间:2024/06/15 14:09

首先说下我的环境。

  1.使用VM创建三个虚拟机安装ubuntu 16.04系统

  2.在ubuntu 16.04系统里安装hadoop2.8.1 并启动成功(安装方法网搜下,一般都差别不大,学习使用配置基本不是很全,但能保证启动成功)。

  3.window7 64位系统上面开发,远程连接hadoop。

  4.安装eclipse插件:hadoop-eclipse-plugin-2.6.0.jar,github上下载地址:https://github.com/winghc/hadoop2x-eclipse-plugin/tree/master/release

把其copy到eclipse的程序目录plugin下,重启eclipse会有hadoop视图会出现(eclipse配置hadoop网上都有差别不大)。

  4.使用eclipse连接hdfs。路径一般为:hdfs:你的IP:9000。如下图:



接下来就是创建mapreduce项目,没有什么可说的。

提示:创建完项目会自动导入你的hadoop目录下所使用的包,前提是在配置eclipse的Hadoop Map/Reduce目录设置好。如果习惯使用maven,可以把项目转成Maven项目
开发程序创建类代码如下:当然这个是hadoop示例里面的一个类,反编译出来运行的WordCount类。

package mapred.first.demo;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;import org.apache.hadoop.util.GenericOptionsParser;public class WordCount{  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> [<in>...] <out>");      System.exit(2);    }    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);    for (int i = 0; i < otherArgs.length - 1; i++) {      FileInputFormat.addInputPath(job, new Path(otherArgs[i]));    }    FileOutputFormat.setOutputPath(job, new Path(otherArgs[(otherArgs.length - 1)]));    System.exit(job.waitForCompletion(true) ? 0 : 1);  }  public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable>  {    private IntWritable result = new IntWritable();    public void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context)      throws IOException, InterruptedException    {      int sum = 0;      for (IntWritable val : values) {        sum += val.get();      }      this.result.set(sum);      context.write(key, this.result);    }  }  public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>  {    private static final IntWritable one = new IntWritable(1);    private Text word = new Text();    public void map(Object key, Text value, Mapper<Object, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException    {      StringTokenizer itr = new StringTokenizer(value.toString());      while (itr.hasMoreTokens()) {        this.word.set(itr.nextToken());        context.write(this.word, one);      }    }  }}
运行里,选择在run as -> run on hadoop 。这个提前要设置两个参数一个是你hadoop的输入目录,一个是hadoop的输出目录(网上示例很多这里不多说)。

充满期待的运行下,但结果就很出错,提示 can not find winutis.exe 文件,那是一个不服啊。网上搜说是在hadoop-home/bin目录下没有winutis.exe ,hadoop.dll文件,找到hadoop目录下查看,果然没有,在网上下载了,最后找到了github.有人编译好的。地址:https://github.com/steveloughran/winutils   找到相关版本下载下来,copy到hadoop-home/bin目录下,再次运行,还是不行。同样的结果。两样的错误。

网上搜索了一翻后,说是要copy到C:\\Windows。照做后,运行没有问题了。也成功出现相要的结果。注意:winutils.exe ,hadoop.dll两个文件都要copy。

但是有一个警告:Did not find winutils.exe: java.io.FileNotFoundException。没有影响程序运行。

不知道什么原因,希望有碰到解决的留言交流下。微笑



阅读全文
0 0
原创粉丝点击