解壓資料當中的 hadoop-2.6.0-cdh5.14.2_windows環境配置安裝包.rar 這個壓縮文件文件到一個沒有中文沒有空格的目錄下java
而後在windows當中配置hadoop的環境變量node
而後將hadoop.dll文件拷貝到C:\Windows\System32apache
注意 若是沒有 配置好windows的hadoop的環境變量,那麼就會報如下錯誤windows
一、首先,須要配置Maven的本地倉庫,遠程倉庫,安裝路徑等(具體參考別人的博客)maven
二、建立Maven工程,導入jar包oop
建立工程參考別人博客,我這隻給下面的 pom.xml 文件內容(最好在沒網的時候建立,不要Enable import Automatic,我這以前總是自動加載包出錯)ui
<repositories> <repository> <id>cloudera</id> <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.6.0-mr1-cdh5.14.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.6.0-cdh5.14.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.6.0-cdh5.14.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>2.6.0-cdh5.14.2</version> </dependency> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.0.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <!-- <verbal>true</verbal>--> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <minimizeJar>true</minimizeJar> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
而後在下面這個文件下建立 .java 文件url
HdfsOpreate.java的內容以下:spa
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.junit.Test; import java.io.IOException; public class HdfsOpreate { @Test public void mkdirToHdfs() throws IOException { Configuration configuration = new Configuration(); //若是是操做hdfs上面的文件,必定要配置fs.defaultFS configuration.set("fs.defaultFS","hdfs://node01:8020"); FileSystem fileSystem = FileSystem.get(configuration); fileSystem.mkdirs(new Path("/kaikeba/dir2")); fileSystem.close(); } @Test public void uploadFile() throws IOException { Configuration configuration = new Configuration(); configuration.set("fs.defaultFS","hdfs://node01:8020"); FileSystem fileSystem = FileSystem.get(configuration); fileSystem.copyFromLocalFile(new Path("E:\\BigDataCode\\Java\\data\\wc\\input\\text1.txt"),new Path("hdfs://node01:8020/kaikeba/dir2")); fileSystem.close(); } @Test public void downloadFile() throws IOException { Configuration configuration = new Configuration(); configuration.set("fs.defaultFS","hdfs://node01:8020"); FileSystem fileSystem = FileSystem.get(configuration); fileSystem.copyToLocalFile(new Path("hdfs://node01:8020/kaikeba/dir1/word.txt"),new Path("E:\\BigDataCode\\Java\\data\\word2.txt")); fileSystem.close(); } }
而後執行代碼。3d
。。。。。。。。諒解諒解,這篇博客寫的很差,緣由是沒有再次重複各個步驟,之後有時間補充。