商城首页欢迎来到中国正版软件门户

您的位置:首页 >Windows 8配置Eclipse与Hadoop2.2.0环境指南

Windows 8配置Eclipse与Hadoop2.2.0环境指南

  发布于2025-07-27 阅读(0)

扫一扫,手机访问

图文详解如何在Windows 8.0上的Eclipse 4.4.0中配置CentOS 6.5上的Hadoop 2.2.0开发环境,供有需要的朋友参考学习。

Eclipse的Hadoop插件下载地址:https://github.com/winghc/hadoop2x-eclipse-plugin

下载压缩包后,解压并将hadoop-eclipse-kepler-plugin-2.2.0.jar文件放置到Eclipse的dropins目录中,重启Eclipse即可。

进入Windows -> Preferences配置根目录。

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境,这里的hadoop installation directory不是指你在Windows上安装的Hadoop目录,而是你在CentOS上编译好的源码在Windows上的解压路径。这个路径仅用于创建MapReduce项目时自动引入所需的jar文件。

进入Window -> Open Perspective -> Other -> Map/Reduce,打开Map/Reduce窗口。

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境找到

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境,右击选择New Hadoop location,这时会出现

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境Map/Reduce(V2)中的配置对应于mapred-site.xml中的端口配置,DFS Master中的配置对应于core-site.xml中的端口配置,配置完成后点击finish即可。这时可以查看

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境进行测试,创建一个新的MapReduce项目,

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境,要解决这个问题,你需要在Windows上配置HADOOP_HOME,并将%HADOOP_HOME%\bin添加到path中。然后从https://github.com/srccodes/hadoop-common-2.2.0-bin下载文件,下载后将bin目录中的内容全部复制到你自己在Windows上的Hadoop bin目录中,覆盖即可。同时,将hadoop.dll添加到C盘的system32目录中。如果完成这些步骤后仍然遇到“Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z”,请检查你的JDK版本,可能是由于使用了32位JDK导致的,需要下载并安装64位JDK,并在Eclipse中将JRE环境配置为新安装的64位JRE。

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境。比如我的jre1.8是64位,而jre7是32位,如果列表中没有你需要的JRE,直接点击add添加即可,选择你的64位JRE环境后,问题就会解决。

接下来编写一个wordcount程序进行测试,下面是我的代码,前提是你已经在HDFS上创建了input文件,并在其中放置了一些内容:

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 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 {
        // System.setProperty("hadoop.home.dir", "E:\\\\hadoop2.2\\\\");
        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("hdfs://master:9000/input"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://master:9000/output"));
        boolean flag = job.waitForCompletion(true);
        System.out.print("SUCCEED!" + flag);
        System.exit(flag ? 0 : 1);
        System.out.println();
    }
}

Windows 8.0上Eclipse 4.4.0 配置CentOS 6.5 上的Hadoop2.2.0开发环境

本文转载于:https://cloud.tencent.com/developer/article/2038863 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注