1.打開vs code軟件,最好創建好自己的工程並使用vs code打開
2. 使用快捷鍵ctrl + shift + p按鍵,輸入maven進行搜索,選中如圖訴訟hi的create mavene project
3.步驟2后,選擇如圖所示的archetype-quickstart-jdk8
4.接下來選擇版本信息,如圖
5. 接下來設置項目路徑

6. 步驟5后出現如圖所示,輸入ctrl+c 關閉窗口

之后在vscod的termial終端面板輸入 mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId="archetype-quickstart-jdk8" -DarchetypeGroupId="com.github.ngeor" -DarchetypeVersion="2.0.0" 然后再添加 -DarchetypeCatalog=internal 再按enter執行
8. 步驟7后,根據提示輸入相關參數
(1)groupid:公司或組織的域名倒序+當前項目名稱
(2)artifactId:當前項目的模塊名稱
(3)version:輸入enter鍵
(4)輸入enter鍵
(5)輸入enter鍵
(6)
9 編寫運行程序
(1)分別編寫HDFSClient.java與HDFSClientTest.java文件,文件位置如圖所示
HDFSClient.java
package com.atguigu.hdfsclient; import java.io.IOException; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.junit.Test; /** * A simple example for hdfsclient. */ public class HDFSClient { @Test public void put() throws IOException, InterruptedException { Configuration conf = new Configuration(); FileSystem fileSystem = FileSystem.get(URI.create("hdfs://hadoop100:9000"), conf, "atguigu"); fileSystem.copyFromLocalFile(new Path("C:\\Users\\DELL\\Desktop\\hadoop\\1.txt"), new Path("/")); fileSystem.close(); System.out.println("it is over"); } }
HDFSClientTest.java
package com.atguigu.hdfsclient; import java.io.IOException; import org.junit.Test; /** * Unit test for simple hdfsclient. */ public class HDFSClientTest { @Test public void testHDFSClient() throws IOException, InterruptedException { HDFSClient hclient = new HDFSClient(); hclient.put(); } }
(2)在terminal終端,先輸入mvn compile后回車 進行編譯 如圖:
(3)在terminal終端,輸入mvn test 后回車 進行測試