Objective:
Learn the configuration of Windows development Hadoop programs.
[0007] Example of an Eclipse development HDFs program under Windows
Too much trouble
[0010] Windows Eclipse Development HDFS Program sample (II)
Output log changes, and configuration seems to be cumbersome.
Environment:
Windows 7 64 under Eclipse
Description
This practice was made after the [0008] Windows 7 Hadoop 2.6.4 Eclipse Local Development Debug configuration was set up,
There are some environment variable settings, plug-ins installed in this area.
If you follow the steps below and have an error, you can refer to this article as well as the question [0009] to resolve
1. New Project
Create a new project, import a Hadoop development package
Detailed reference
[0007] Windows Eclipse Development HDFs Program Example 1 new project
2. Create a new class and write the following code
1 PackageHDFs;2 3 Importjava.io.FileNotFoundException;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 7 Importorg.apache.commons.compress.utils.IOUtils;8 Importorg.apache.hadoop.conf.Configuration;9 ImportOrg.apache.hadoop.fs.FSDataInputStream;Ten ImportOrg.apache.hadoop.fs.FileSystem; One ImportOrg.apache.hadoop.fs.Path; A - /** - * Function: Download hdfs://ssmaster:9000/data/paper.txt to Windows C:\paper.txt the * Calling Method: Hadoop jar package name. Jar - */ - - Public classDown_load { + - Public Static voidMain (string[] args) { + AConfiguration conf =NewConfiguration (); atConf.set ("Fs.defaultfs", "Hdfs://ssmaster:9000/"); - -FileSystem fs =NULL; -Path src =NULL; -Fsdatainputstream in =NULL; -FileOutputStream out =NULL; in -src =NewPath ("Hdfs://ssmaster:9000/data/paper.txt" ); to + Try { - theFS =filesystem.get (conf); *in =Fs.open (SRC); $ Panax Notoginseng}Catch(IOException e) { - e.printstacktrace (); the } + A Try { theout =NewFileOutputStream ("C:\\paper.txt");//equivalent C:/paper.txt +}Catch(FileNotFoundException e) { - e.printstacktrace (); $ } $ - Try { - ioutils.copy (in, out); the}Catch(IOException e) { - e.printstacktrace ();Wuyi } the - } Wu}
View Code
Remark: Add Conf.set ("Fs.defaultfs", "hdfs://ssmaster:9000/") to the code of Step 2nd of [0007];
3 execution
Right-click->run Java application
Summary:
The Windows Development environment under HDFS is basically well-built.
[0011] Windows Eclipse Development HDFS Program sample (III)