Maven构件Hadoop1.x以及Hadoop2.x项目

参看文档

http://blog.csdn.net/tryhl/article/details/43967441


也可以关注我的另外一篇文章http://www.aboutyun.com/blog-12709-1768.html

也可以加入群 316297243一起学习讨论

此文章用于学习和交流,转载请注明

1   Hadoop1.xMaven项目构建

  怎么用Maven构建项目,以及怎么构建hadoop项目,这里就不详细介绍,详情请参考

   http://blog.csdn.net/tryhl/article/details/43967441

   这里只讲述在用maven构建hadoop1.x项目以及导入Eclipse运行需要注意的问题以及产生的问题。

 1)修改pom.xml文件

我依赖的是hadoop-1.2.1版本的

加入如下依赖

  

 <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-core</artifactId>
      <version>1.2.1</version>
  </dependency>

加入依赖之后等待下载相关的jar

   2)从hadoop集群中下载配置文件

     这里不加也行

  下载配置文件:

       core-site.sh

       hdfs-site.sh

       mapred-site.sh

      把配置文件加入/main/java/resources/hadoop文件夹下   

     

           3) 加入WordCount源码

public class WordCount {

	public static class WordCountMapper extends MapReduceBase implements

	Mapper<Object, Text, Text, IntWritable> {

		private final static IntWritable one = new IntWritable(1);

		private Text word = new Text();

		@Override
		public void map(Object key, Text value,

		OutputCollector<Text, IntWritable> output, Reporter reporter)

		throws IOException {

			StringTokenizer itr = new StringTokenizer(value.toString());

			while (itr.hasMoreTokens()) {

				word.set(itr.nextToken());

				output.collect(word, one);

			}

		}

	}

	public static class WordCountReducer extends MapReduceBase implements

	Reducer<Text, IntWritable, Text, IntWritable> {

		private IntWritable result = new IntWritable();

		@Override
		public void reduce(Text key, Iterator<IntWritable> values,

		OutputCollector<Text, IntWritable> output, Reporter reporter)

		throws IOException {

			// TODO Auto-generated method stub

			int sum = 0;

			while (values.hasNext()) {

				sum += va
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值