本文共 911 字,大约阅读时间需要 3 分钟。
上一篇说到的方式采用的hadoop-local.xml中的配置,在执行是设置了Program Arguments,如果嫌麻烦,还有一种思路,在代码里写配置如下:效果和原理上一篇中的一样,不过改成了写到代码里。
public static void main(String[] args) throws Exception { //配置本地模式 Configuration conf = new Configuration(); conf.set("fs.defaultFS", "file:///"); conf.set("mapreduce.jobtracker.address", "local"); //输入数据 Path input = new Path("D:/temperData.data"); //输出目录 Path output = new Path("D:/mnt/temperoutput/999/"); //删除原有输出目录 FileSystem fs = FileSystem.get(conf); fs.delete(output, true); MaxTemperatureDriver driver = new MaxTemperatureDriver(); //设置配置文件 driver.setConf(conf); int extCode = driver.run(new String[]{input.toString(),output.toString()}); System.out.println("exit code : "+extCode); }不过环境变量还是需要配置的: HADOOP_HOME指向Hadoop解压目录 PATH中加入%HADOOP_HOME%bin 或者在debug/run Configuration 的 VM参数中加入: -Dhadoop.home.dir=D:\IT\hadoop-2.7.2 Environments环境变量中加入: PATH %PATH%;D:/xxx/Hadoop/bin
转载地址:http://vppef.baihongyu.com/