1.环境
Jdk:1.6.0_10-rc2
Hadoop:hadoop-1.0.0.tar.gz
Eclipse 版本:3.4.0
Hadoop Eclipse 插件 :hadoop-eclipse-plugin-1.0.0.jar
操作系统:Windows7 32位 旗舰版
2.Eclipse插件配置
2.1 把"hadoop-eclipse-plugin-1.0.0.jar"放到Eclipse的目录的"plugins"中(eclipse/plugins),重新启动Eclipse生效
2.2 选择Elipse Window菜单下的"Preference",配置"Hadoop Map/Reduce"选项,选择Hadoop的安装根目录
2.3 配置Hadoop Location
在配置Hadoop Location之前 确定hadoop 已启动起来
Eclipse 切换到“Map/Reduce Locations” 视图 , 在"Map/Reduce Locations"视图右击 选择"New Hadoop Location",
* Map/Reduce Master与mapred-site.xml配置文件对应
* DFS Mast 与core-site.xml配置对应创建完成后 ,切换到JavaEE视图 刷新右边的DFS Locations 就会看到dfs文件结构
可以在节点上右键 创建 删除目录做测试
3.运行wordCount例子程序
创建一个 Map/Reduce Project项目
创建成功后 WordCount报名对应(源码在hadoop\src\examples\org\apache\hadoop\examples目录下)
WordCount.java
package org.apache.hadoop.examples;import java.io.IOException;import java.net.URI;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataInputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.FileUtil;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IOUtils;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
运行例子
1.点击WordCount.java,右键-->Run As-->Run Configurations
2.在弹出的Run Configurations对话框中,点Java Application,右键-->New,这时会新建一个application名为WordCount 3.配置参数,点Arguments,在Program arguments中配置 /user/admin/input /user/admin/output 4.运行时可能会抛出java.lang.OutOfMemoryError: Java heap space异常 配置VM arguments(在Program arguments下) -Xms512m -Xmx512m -XX:PermSize=96m5.右键-->Run on Hadoop 刷新右边的DFS Locations 就会看到结果