第一步:下载eclipse-jee-kepler-SR2-linux-gtk-x86_64.tar.gz

注意:如果电脑是64位,就下载linux下的64位eclipse,不要下载32位的eclipse,不然会无法启动eclipse

第二步:下载最新版本的hadoop插件

重命名:将下载的插件重命名为"hadoop-eclipse-plugin-1.1.1.jar"

将hadoop-eclipse-plugin-1.1.1.jar复制到eclipse/plugins目录下,重启eclipse。

第三步:配置hadoop路径

Window-> Preferences选择 “HadoopMap/Reduce”,点击“Browse...”选择Hadoop文件夹的路径。

这个步骤与运行环境无关,只是在新建工程的时候能将hadoop根目录和lib目录下的所有jar包自动导入。

第四步:添加一个MapReduce环境

在eclipse下端,控制台旁边会多一个Tab,叫“Map/ReduceLocations”,在下面空白的地方点右键,选择“NewHadoop
location...”,如图所示:

第五步:使用eclipse对HDFS内容进行修改

经过上一步骤,左侧“ProjectExplorer”中应该会出现配置好的HDFS,点击右键,可以进行新建文件夹、删除文件夹、上传文件、下载文件、删除文件等操作。注意:每一次操作完在eclipse中不能马上显示变化,必须得刷新一下。

在hadoop下新建input文件夹,在input目录下新建两个文件file01.txt,file02.txt

file01.txt内容如下:

hello hadoop

file02.txt内容如下:

hello world

上传本地文件到hdfs:(在终端下)

首先创建input

bin/hadoop fs -mkdir /input

上传

hadoopfs -put input/× /input

第六步:创建工程

File-> New -> Project选择“Map/ReduceProject”,然后输入项目名称,创建项目。插件会自动把hadoop根目录和lib目录下的所有jar包导入。

第七步:新建一个WordCount.java(注意包名要相同),代码如下:

<span style="font-family:SimHei;font-size:14px;">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;
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 {
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(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}</span>

第八步:运行WordCount

1.选择Run As-》Run Configurations,将其对话框下的Argument改为如下(main方法的参数传递)

hdfs://localhost:9000/input

hdfs://localhost:9000/output

2.运行之前,删除output文件。Run As -> Run on Hadoop 选择之前配置好的MapReduce运行环境,点击“Finish”运行。

3.

查看运行结果:

在输出目录中,可以看见WordCount程序的输出文件。除此之外,还可以看见一个logs文件夹,里面会有运行的日志。

Ubuntu下eclipse开发hadoop应用程序环境配置的更多相关文章

  1. Linux下使用Eclipse开发Hadoop应用程序

    在前面一篇文章中介绍了如果在完全分布式的环境下搭建Hadoop0.20.2,现在就再利用这个环境完成开发. 首先用hadoop这个用户登录linux系统(hadoop用户在前面一篇文章中创建的),然后 ...

  2. Ubuntu杂记——Ubuntu下Eclipse搭建Maven、SVN环境

    正在实习的公司项目是使用Maven+SVN管理的,所以转到Ubuntu下也要靠自己搭环境,自己动手,丰衣足食.步骤有点简略,但还是能理解的. 一.安装JDK7 打开终端(Ctrl+Alt+T),输入  ...

  3. Hadoop实战-使用Eclipse开发Hadoop API程序(四)

    一.准备运行所需Jar包 1)avro-1.7.4.jar 2)commons-cli-1.2.jar 3)commons-codec-1.4.jar 4)commons-collections-3. ...

  4. windows环境下Eclipse开发MapReduce程序遇到的四个问题及解决办法

    按此文章<Hadoop集群(第7期)_Eclipse开发环境设置>进行MapReduce开发环境搭建的过程中遇到一些问题,饶了一些弯路,解决办法记录在此: 文档目的: 记录windows环 ...

  5. 【ARM-Linux开发】Linux环境下使用eclipse开发C++动态链接库程序

    Linux环境下使用eclipse开发C++动态链接库程序 Linux中也有类似windows中DLL的变成方法,只不过名称不同而已.在Linux中,动态链接叫做Standard Object,生成的 ...

  6. Ubuntu下Java开发环境搭建(eclipse)

    最近把工作环境转移到了Ubuntu Kylin下,发现在这下面Java环境还是很方便的.然而也经历了一些摸索的过程,故作文以记之. 一/开发前准备 安装系统/配置软件源,这部分内容没什么需要注意的.O ...

  7. Ubuntu下Eclipse中运行Hadoop程序的参数问题

    需要统一的参数: 当配置好eclipse中hadoop的程序后,几个参数需要统一一下: hadoop安装目录下/etc/core_site.xml中 fs.default.name的端口号一定要与ha ...

  8. 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 ...

  9. [b0007] windows 下 eclipse 开发 hdfs程序样例

    目的: 学习使用hdfs 的java命令操作 相关: 进化: [b0010] windows 下 eclipse 开发 hdfs程序样例 (二) [b0011] windows 下 eclipse 开 ...

随机推荐

  1. jQuery Ajax传递数组到asp.net web api参数为空

    前端: var files = []; files.push({ FileName: "1.jgp", Extension: ".jgp", FileType: ...

  2. js分秒必争

    将函数和对象合写在一起时,函数就变成了“方法”(method): //当函数赋值给对象的属性,我们称之为 //方法.所有的JavaScript的对象都含有方法 var a=[];        //创 ...

  3. 消除a标签点击后产生的虚线框

    为a标签添加这条属性: a:focus {outline:none;-moz-outline:none;}

  4. Python的包管理工具Pip (zz )

    Python的包管理工具Pip 接触了Ruby,发现它有个包管理工具RubyGem很好用,并且有很完备的文档系统http://rdoc.info 发现Python下也有同样的工具,包括easy_ins ...

  5. 手机GPS为什么能在室内定位?

      为什么手机在室内也能定位?大部分人知道手机会通过GPS进行定位,其实手机定位系统并不是和我们的RTK完全一样的,因为那样就无法解释为何在室内也能定位了,这里我来科普一下智能手机的那些定位方法.   ...

  6. fatal error: call to undefined function imagettftext

    参照:http://stackoverflow.com/questions/7290958/php-fatal-error-call-to-undefined-function-imagettftex ...

  7. 通过Guid获取DirectoryEntry对象

    绑定DirectoryEntry对象通常有两种方法,一种是通过字符串(如通过ADsPath),一种是通过Guid(参见:http://msdn.microsoft.com/zh-cn/library/ ...

  8. HttpWebRequest 请求数据

    string fullUrl = "http://vip.AAA.cn/PreviewInterfaceAction.action?code=vip0008&data_digest= ...

  9. Accordion - 手风琴

    //手风琴效果 <div style="overflow:hidden;height:400px;width:948px;"> <div class=" ...

  10. eclipse js 引用跳转

    引用 http://stackoverflow.com/questions/24505993/the-resource-is-not-on-the-build-path-of-a-javascript ...