1.配置Maven
2.修改本地倉庫位置
3.配置鏡像地址
4.pom文件配置
<dependencies>
<dependency>
? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>
? ? ? ? ? ? <artifactId>hadoop-common</artifactId>
? ? ? ? ? ? <version>2.8.4</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>
? ? ? ? ? ? <artifactId>hadoop-hdfs</artifactId>
? ? ? ? ? ? <version>2.8.4</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>
? ? ? ? ? ? <artifactId>hadoop-client</artifactId>
? ? ? ? ? ? <version>2.8.4</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.projectlombok</groupId>
? ? ? ? ? ? <artifactId>lombok</artifactId>
? ? ? ? ? ? <version>1.16.10</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>log4j</groupId>
? ? ? ? ? ? <artifactId>log4j</artifactId>
? ? ? ? ? ? <version>1.2.17</version>
? ? ? ? ? ? 下載插件
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.slf4j</groupId>
? ? ? ? ? ? <artifactId>slf4j-api</artifactId>
? ? ? ? ? ? <version>1.7.7</version>
? ? ? ? </dependency>
? ? ? ? <!-- https://mvnrepository.com/artifact/junit/junit -->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>junit</groupId>
? ? ? ? ? ? <artifactId>junit</artifactId>
? ? ? ? ? ? <version>4.12</version>
? ? ? ? ? ? <scope>test</scope>
? ? ? ? </dependency>
? </dependencies>
編寫使用Hadoop
public class HdfsClientDemo1 {
public static void main(String[] args) throws Exception {
// 1 獲取文件系統(tǒng)
Configuration configuration = new Configuration();
// 配置在集群上運(yùn)行
configuration.set("fs.defaultFS", "hdfs://bigdata111:9000");
FileSystem fileSystem = FileSystem.get(configuration);
// 直接配置訪問集群的路徑和訪問集群的用戶名稱
// FileSystem fileSystem = FileSystem.get(new URI("hdfs://bigdata111:9000"),configuration, "itstar");
// 2 把本地文件上傳到文件系統(tǒng)中
fileSystem.copyFromLocalFile(new Path("f:/hello.txt"), new Path("/hello1.copy.txt"));
// 3 關(guān)閉資源
fileSystem.close();
System.out.println("over");}}