你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu下Eclipse开发Hadoop应用程序环境配置

[日期:2013-01-21] 来源:Linux社区  作者:xiaotom5 [字体:大 中 小]

第七步:新建一个WordCount.java,这里使用系统自带的TokenCountMapper和LongSumReducer,代码如下:

package com.baison.action;
import org.apache.Hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.lib.TokenCountMapper;
import org.apache.hadoop.mapred.lib.LongSumReducer;
public class WordCount {
 public static void main(String[] args) {
  JobClient client = new JobClient();
  JobConf conf = new JobConf(WordCount.class);
  String[] arg = { "hdfs://localhost:9100/user/tanglg1987/input",
    "hdfs://localhost:9100/user/tanglg1987/output" };
  FileInputFormat.addInputPath(conf, new Path(arg[0]));
  FileOutputFormat.setOutputPath(conf, new Path(arg[1]));
  conf.setOutputKeyClass(Text.class);
  conf.setOutputValueClass(LongWritable.class);
  conf.setMapperClass(TokenCountMapper.class);
  conf.setCombinerClass(LongSumReducer.class);
  conf.setReducerClass(LongSumReducer.class);
  client.setConf(conf);
  try {
   JobClient.runJob(conf);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

linux
相关资讯       Ubuntu Hadoop  Ubuntu Eclipse  Ubuntu Hadoop配置 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/7/31 10:57:40
对Hadoop版本有要求?用hadoop-0.20.2老是连接错误呢