window下eclipse配制hadoop插件 (四)

1.把插件hadoop-eclipse-plugin-2.6.2.jar拷贝到eclipse安装目录下的plugins中

2.重启一下Eclipse

配制hadoop

3.进入map/reduce视图模式

4.向hadoop分布式存储系统中存入数据

5.连接hadoop

6.创建hadoop工程

7.创建类MyWordCount.java

package com.yc.hadoop;
import java.io.IOException;
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 MyWordCount {
          public static class MyWordCountMapper 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 {
                      String[] words = value.toString().split("\\s");
                      for (String w : words) {
                            word.set(w);
                            context.write(word, one);
                      }
                }
          }

          public static class MyWordCountReducer 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, "mywordcount");
                job.setJarByClass(MyWordCount.class);
                job.setMapperClass(MyWordCountMapper.class);
                job.setCombinerClass(MyWordCountReducer.class);
                job.setReducerClass(MyWordCountReducer.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);
          }
    }

8.运行hadoop项目

时间: 2024-10-29 19:06:11

window下eclipse配制hadoop插件 (四)的相关文章

Ubuntu 14.10 下Eclipse安装Hadoop插件

准备环境 1 安装好了Hadoop,之前安装了Hadoop 2.5.0,安装参考http://www.cnblogs.com/liuchangchun/p/4097286.html 2 安装Eclipse,这个直接在其官网下载即可 安装步骤 1 下载Eclipse插件,我找的是Hadoop 2.2 的插件,在Hadoop 2.5 下可以正常用,获取插件这里有两种方式 1.1 一是自己下载源码自己编译,过程如下 首先,下载eclipse-hadoop的插件,网址是https://github.co

windows下eclipse调试hadoop详解

1)下载Eclipse http://www.eclipse.org/downloads/ Eclipse Standard 4.3.2 64位 2) 下载hadoop版本对应的eclipse插件 我的hadoop是1.0.4,因此下载hadoop-eclipse-plugin-1.0.4.jar 下载地址:http://download.csdn.net/detail/m_star_jy_sy/7376169 3)安装hadoop插件 将hadoop-eclipse-plugin-1.0.4.

Win下Eclipse提交Hadoop程序出错:org.apache.hadoop.security.AccessControlException: Permission denied: user=D

描述:在Windows下使用Eclipse进行Hadoop的程序编写,然后Run on hadoop 后,出现如下错误: 11/10/28 16:05:53 INFO mapred.JobClient: Running job: job_201110281103_000311/10/28 16:05:54 INFO mapred.JobClient: map 0% reduce 0%11/10/28 16:06:05 INFO mapred.JobClient: Task Id : attemp

Windows下Eclipse连接hadoop

? hadoop在虚拟机上(远程连接也是一样只需要知道master的ip和core-site.xml配置即可. Vmware上搭建了hadoop分布式平台: ? 192.168.11.134 master 192.168.11.135 slave1 192.168.11.136 slave2 ? core-site.xml 配置文件: <property> ????????<name>fs.defaultFS</name> ????????<value>hd

[hadoop]Windows下eclipse导入hadoop源码,编译WordCount

hadoop版本为hadoop1.2.1 eclipse版本为eclipse-standard-kepler-SR2-win32-x86_64 WordCount.java为hadoop-1.2.1\src\examples\org\apache\hadoop\examples\WordCount.java 1 /** 2 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * you may not

Hadoop学习笔记0004——eclipse安装hadoop插件

Hadoop学习笔记0004--eclipse安装hadoop插件 1.下载hadoop-1.2.1.tar.gz,解压到win7下hadoop-1.2.1: 2.如果hadoop-1.2.1中没有hadoop-eclipse-plugin-1.2.1.jar包,就到网上下载下来: 3.关闭eclipse,然后将hadoop-eclipse-plugin-1.2.1.jar拷贝到eclipse安装目录下的eclipse-x.x\plugins文件夹下,重启eclipse 4.在eclipse中顶

eclipse配置hadoop插件

eclipse配置hadoop插件:

实验二-1 win7下给eclipse安装hadoop插件

使用的教程为: 1. windows7+eclipse+hadoop2.5.2环境配置 http://www.cnblogs.com/huligong1234/p/4137133.html 2. Hadoop 在Windows7操作系统下使用Eclipse来搭建Hadoop开发环境 http://www.linuxidc.com/Linux/2014-12/111061.htm 3. eclipse_win7_hadoop1.2.1开发环境搭建1 http://blog.csdn.net/maj

Linux下为Eclipse安装hadoop插件

前提条件:在Linux系统中已经安装好了jdk和hadoop 本文的安装环境:1.arch Linux 2. hadoop1.0.1本地伪分布模式安装  3. Eclipse 4.5 1. 下载Eclipse 的Linux版本(http://www.eclipse.org/downloads/?osType=linux) ,选择IDE for Java EE,注意要下载Package,不要下载Installer. 2. 将下载好的压缩包解压的到软件的安装目录,此时Eclipse可以使用,后面的工