首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Eclipse配置Hadoop MapReduce开发环境

Eclipse配置Hadoop MapReduce开发环境

作者头像
星哥玩云
发布2022-06-29 21:26:33
发布2022-06-29 21:26:33
7710
举报
文章被收录于专栏:开源部署开源部署

环境:

Eclipse版本:MyEclipse6.5.1

Hadoop版本:hadoop-1.2.1

1.安装MyEclipse后,创建一个java项目

File->New->Java Project

输入项目名称,确定

2.导入hadoop所有包

解压hadoop-1.2.1.tar(E:\software\share\hadoop-1.2.1)

把E:\software\share\hadoop-1.2.1下

和E:\software\share\hadoop-1.2.1\lib下的jar包都导入到项目里

方法如下:

点中项目根右键->Properties->JavaPath->Libraries->Add External JARs

3.确认jre为6.0以上版本

我的MyEclipse6.5.1版本开始默认使用jre5.0版本,因hadoop-1.2.1需要jre 6.0以上版本,所执行程序时报错:

Bad version number in .class file (unableto load class ***)

更改jre版本方法

Windows->Preference->Java->InstalledJREsàadd

4.修改FileUtil.java文件

这时在创建一个测试WordCount的mapreduce程序时,同样遇到了下面的问题

13/12/13 22:58:49 WARNutil.NativeCodeLoader: Unable to load native-hadoop library for yourplatform... using builtin-java classes where applicable

13/12/13 22:58:49 ERRORsecurity.UserGroupInformation:PriviledgedActionExceptionas:liczcause:java.io.IOException: Failed to set permissions of path:\tmp\hadoop-licz\mapred\staging\licz1853164772\.staging to 0700

Exception in thread"main"java.io.IOException: Failed to set permissions of path:\tmp\hadoop-licz\mapred\staging\licz1853164772\.staging to

......

解决办法:

修改E:\software\share\hadoop-1.2.1\src\core\org\apache\hadoop\fs\FileUtil.java文件

注释掉下面的内容

685 private static voidcheckReturnValue(boolean rv, File p,

686 FsPermission permission

687 ) throws IOException {

688 /*if (!rv) {

689 throw new IOException("Failed toset permissions of path: " + p +

690 " to " +

691 String.format("%04o", permission.toShort()));

692 }*/

693 }

然后在Mapreduce1/scr新建一个org.apache.hadoop.fs包,把FileUtil.java文件拷到这个包的下面(在eclipse里直接粘贴就可以)

再次编译WordCount.java程序没有报错

import java.io.IOException; import java.util.Iterator; import java.util.StringTokenizer;

import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.FileInputFormat; importorg.apache.hadoop.mapred.FileOutputFormat; importorg.apache.hadoop.mapred.JobClient; importorg.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.MapReduceBase; importorg.apache.hadoop.mapred.Mapper; importorg.apache.hadoop.mapred.OutputCollector; importorg.apache.hadoop.mapred.Reducer; importorg.apache.hadoop.mapred.Reporter; importorg.apache.hadoop.mapred.TextInputFormat; importorg.apache.hadoop.mapred.TextOutputFormat;

public class WordCount {

    public static class WordCountMapper extends MapReduceBase implementsMapper<Object, Text, Text, IntWritable> {         private final static IntWritable one = new IntWritable(1);         private Text word = new Text();

        public void map(Object key, Text value,OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {             StringTokenizer itr = newStringTokenizer(value.toString());             while (itr.hasMoreTokens()) {                 word.set(itr.nextToken());                 output.collect(word, one);             }

        }     }

    public static class WordCountReducer extends MapReduceBase implementsReducer<Text, IntWritable, Text, IntWritable> {         private IntWritable result = new IntWritable();

        public void reduce(Text key, Iterator<IntWritable>values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {             int sum = 0;             while (values.hasNext()) {                 sum +=values.next().get();             }             result.set(sum);             output.collect(key, result);         }

    }

    public static void main(String[] args) throws Exception {         String input = "hdfs://192.168.2.100:9000/user/licz/hdfs/o_t_account";         String output = "hdfs://192.168.2.100:9000/user/licz/hdfs/o_t_account/result";

        JobConf conf = new JobConf(WordCount.class);         conf.setJobName("WordCount");         conf.addResource("classpath:/hadoop/core-site.xml");         conf.addResource("classpath:/hadoop/hdfs-site.xml");         conf.addResource("classpath:/hadoop/mapred-site.xml");

        conf.setOutputKeyClass(Text.class);         conf.setOutputValueClass(IntWritable.class);

      conf.setMapperClass(WordCountMapper.class);       conf.setCombinerClass(WordCountReducer.class);       conf.setReducerClass(WordCountReducer.class);

      conf.setInputFormat(TextInputFormat.class);         conf.setOutputFormat(TextOutputFormat.class);

        FileInputFormat.setInputPaths(conf, new Path(input));         FileOutputFormat.setOutputPath(conf,new Path(output));

        JobClient.runJob(conf);         System.exit(0);     }

}

注意:

在windows上使用eclipse用户要与hadoop服务器上安装hadoop的用户名一致,这样才能正常运行,否则会出现没有权限创建目录的报错。

如hadoop安装在了linux服务器的licz用户下,我必需在windows的上的licz用户下使用eclipse开发程序。

这样,我们就可以在eclipse上开发mapreduce程序了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档