標籤:環境 jar ati ica ges out main system nbsp
目的:
學習windows 開發hadoop程式的配置
相關:
[0007] windows 下 eclipse 開發 hdfs程式範例
環境:
基於以下環境配置好後。
[0008] Windows 7 下 hadoop 2.6.4 eclipse 本地開發調試配置
1. 建立HDFS下載檔案類
在已有mapreduce項目中建立類添加如下代碼,代碼從[0007]中取出小修改
功能:從hdfs下載檔案到windows本地
package hadoop.hdfs;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.apache.commons.compress.utils.IOUtils;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataInputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;/** * 功能: 將 hdfs://ssmaster:9000/data/paper.txt下載到Windows下c:\paper.txt * 調用方式:hadoop jar 打包包名.jar */public class Hdfs_Download { public static void main(String[] args) { Configuration conf =new Configuration(); FileSystem fs = null; Path src = null; FSDataInputStream in = null; FileOutputStream out = null; // src = new Path("hdfs://ssmaster:9000/data/paper.txt" ); src = new Path("hdfs://ssmaster:9000/data/paper.txt" ); try { fs = FileSystem.get(conf) ; in = fs.open(src); } catch (IOException e) { e.printStackTrace(); } try { out = new FileOutputStream ("c:\\paper.txt"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { IOUtils.copy(in, out); } catch (IOException e) { e.printStackTrace(); }}}View Code
2.複製hadoop配置好的core-site.xml,hdfs-site.xml,mapred-site.xml到src目錄下
3 運行
右鍵類名,運行為 java application,正常會執行成功
異常
參考[0009]hadoop異常處理,一般都是設定檔沒有
總結:
比[0007]打包執行方便一些。
存在問題:
如果打包到linux下執行,需要修改路徑
如何在eclipse中,直接跑程式,下載hdfs到linxu本地
[0010] windows 下 eclipse 開發 hdfs程式範例 (二)