-
安装Eclipse
下载Eclipse(点击进入下载),解压安装。我安装在/usr/local/software/目录下。
-
在eclipse上安装hadoop插件
下载hadoop插件(点击进入下载) 把插件放到eclipse/plugins目录下。
-
重启eclipse,配置hadoop installation directory
如果安装插件成功,打开Window–>Preferens,你会发现Hadoop Map/Reduce选项,在这个选项里你需要配置Hadoop installation directory。配置完成后退出。
-
配置Map/Reduce Locations
在Window–>Show View中打开Map/Reduce Locations。
在Map/Reduce Locations中新建一个Hadoop Location。在这个View中,右键–>New Hadoop Location。在弹出的对话框中你需要配置Location name,如Hadoop1.0,还有Map/Reduce Master和DFS Master。这里面的Host、Port分别为你在mapred-site.xml、core-site.xml中配置的地址及端口。如:
Map/Reduce Master
192.168.239.130
9001
DFS Master
192.168.239.130
9000
配置完后退出。点击DFS Locations–>Hadoop如果能显示文件夹(2)说明配置正确,如果显示”拒绝连接”,请检查你的配置。
-
新建WordCount项目
File—>Project,选择Map/Reduce Project,输入项目名称WordCount等。
在WordCount项目里新建class,名称为WordCount,代码如下:
package WordCount;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
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;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class WordCount extends Configured implements Tool{
/**
*
* @author root
*
*/
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);
}
}
}
/**
*
* @author root
*
*/
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);
}
}
/**
*
* @param args
* @return
* @throws Exception
*/
public int run(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]));
job.waitForCompletion(true);
return job.isSuccessful() ? 0: 1;
}
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new WordCount(), args);
System.exit(res);
}
}
-
配置运行参数
在弹出的Run Configurations对话框中,点Java Application,右键–>New,这时会新建一个application名为WordCount 配置运行参数,点Arguments,在Program arguments中输入“你要传给程序的输入文件夹和你要求程序将计算结果保存的文件夹”。
-
点击Run,运行程序
点击Run,运行程序,过段时间将运行完成,等运行结束后,查看运行结果,使用命令: hadoop dfs -ls wordcountOutput查看例子的输出结果,发现有两个文件夹和一个文件,使用命令查看part-r-00000文件, hadoop dfs -cat wordcountOutput/part-r-00000可以查看运行结果。
也可以从Eclipse上查看运行结果:
<script type="text/javascript">
$(function () {
$('pre.prettyprint code').each(function () {
var lines = $(this).text().split('\n').length;
var $numbering = $('<ul/>').addClass('pre-numbering').hide();
$(this).addClass('has-numbering').parent().append($numbering);
for (i = 1; i <= lines; i++) {
$numbering.append($('<li/>').text(i));
};
$numbering.fadeIn(1700);
});
});
</script>
分享到:
相关推荐
基于Eclipse的Hadoop应用开发环境配置
基于Eclipse的Hadoop应用开发环境的配置,叫你一步步的配置一个属于自己的Hadoop环境。
基于Eclipse的Hadoop应用开发环境的配置,详细地实践了再eclipse平台上进行hadoop开源的云开发...
Hadoop Eclipse是Hadoop开发环境的插件,用户在创建Hadoop程序时,Eclipse插件会自动导入Hadoop编程接口的jar文件,这样用户就可以在Eclipse插件的图形界面中进行编码、调试和运行Hadop程序,也能通过Eclipse插件...
hadoop-eclipse-plugin-2.6.4.jar。 基于Eclipse的Hadoop应用开发环境配置工具包 jar包
Hadoop-Eclipse开发环境配置是搭建完hadoop环境后,进行代码编写必要的环境,
Hadoop安全分布式的Eclipse开发环境配置,附图片讲解。
windows上建立hadoop+eclipse开发环境
hadoop-eclipse-plugin-2.6.4.jar。 基于Eclipse的Hadoop应用开发环境配置工具包 jar包
hadoop0.20.2的eclipse3.3.2插件及开发环境帮助文档
附件包含eclipse在window7配置hadoop2.7.x 开发环境需要的jar、dll。具体安装步骤可以参考:https://blog.csdn.net/wudichengyaojin/article/details/64440655 可能遇到的问题参考: ...
CentOS上搭建Hadoop并配置Eclipse开发环境
超详细hadoop与eclipse开发环境设置.docx
eclipse连接hadoop搭建mapreduce开发环境。本资源含有hadoop-2.8.5.tar和在eclipse配置mapreduce环境的plugin的jar包,版本为2.8.5
。。。
。。。
Hadoop-Eclipse-Plugin-2.7.3,其中包含hadoop-eclipse-plugin-2.7.3.jar和Windows-Eclipse下配置Hadoop Map/Reduce开发环境所需的相关文件。
目的很简单,为进行研究与学习,部署一个hadoop运行环境,并搭建一个hadoop开发与测试环境。 具体目标是: 1.在ubuntu系统上部署hadoop 2.在windows 上能够使用eclipse连接ubuntu系统上部署的hadoop进行开发与测试 3...
主要内容是完成了eclipse环境下跑wordcount程序的实验
hadoop2.7.1的eclipse插件,编译环境,eclipse 4.4(luna) ,jdk1.7,ant1.9.6,maven3.3,hadoop2.7.1,centos6.7,jdk1.7 要注意的是开发黄金下jdk版本必须是jdk1.7及以上,否则无法使用