복붙노트

[HADOOP] 어떻게하면 hdfs에서 java로 새로운 디렉토리를 만들 수 있습니까?

HADOOP

어떻게하면 hdfs에서 java로 새로운 디렉토리를 만들 수 있습니까?

public static void main(String[] args) throws IOException, URISyntaxException 

{             구성 config = 새 구성 ();

  config.set("fs.default.name","hdfs://127.0.0.1:50070/dfshealth.jsp");

  FileSystem dfs = FileSystem.get(config);
  String dirName = "TestDirectory";

  Path src = new Path(dfs.getWorkingDirectory()+"/"+dirName);

  dfs.mkdirs(src); 

} }

예외가 있었다.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration
    at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<init>(DefaultMetricsSystem.java:37)
    at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.<clinit>(DefaultMetricsSystem.java:34)
    at org.apache.hadoop.security.UgiInstrumentation.create(UgiInstrumentation.java:51)
    at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:217)
    at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:185)
    at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:237)
    at org.apache.hadoop.security.KerberosName.<clinit>(KerberosName.java:79)
    at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:210)
    at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:185)
    at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:237)
    at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:482)
    at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:468)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:1519)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1420)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:123)
    at com.TestConnection.main(TestConnection.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 17 more

구성이 사실 임 문제가 뭐야? 어떤 도움 !!!

해결법

  1. ==============================

    1.문제가 발생하면 commons-configuration-1.6.jar jar를 추가해야합니다.

    문제가 발생하면 commons-configuration-1.6.jar jar를 추가해야합니다.

    나는 아래에 필요한 병들을 나열했다.

    { 
       Configuration config = new Configuration();
       config.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
       config.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
    
       config.set("fs.hdfs.impl", 
                org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()
            );
           config.set("fs.file.impl",
                org.apache.hadoop.fs.LocalFileSystem.class.getName()
            );
      FileSystem dfs = FileSystem.get(config);
      String dirName = "TestDirectory";
      System.out.println(dfs.getWorkingDirectory() +" this is from /n/n");
      Path src = new Path(dfs.getWorkingDirectory()+"/"+dirName);
    
       dfs.mkdirs(src); 
    
    } }
    

    빌드 경로에 다음과 같은 jar 목록을 추가해야합니다.

    commons-cli-1.2.jar

    commons-collections-3.2.1.jar

    commons-configuration-1.6.jar

    commons-lang-2.5.jar

    commons-logging-1.1.1.jar

    구아바 -11.0.2.jar

    hadoop-auth.jar

    hadoop-common.jar

    protobuf-java-2.4.0a.jar

    slf4j-api-1.6.1.jar

    인물 4h-1.2.17pm

    hadoop-hdfs.jar

    cloudera라면 hadoop / lib 폴더에있는이 모든 항아리.

  2. ==============================

    2.Apache Commons Configuration 종속성이 누락되었습니다. 항아리를 다운로드하여 빌드 / 클래스 경로에 추가하십시오.

    Apache Commons Configuration 종속성이 누락되었습니다. 항아리를 다운로드하여 빌드 / 클래스 경로에 추가하십시오.

  3. from https://stackoverflow.com/questions/28832109/how-can-i-make-a-new-directory-in-hdfs-with-java by cc-by-sa and MIT license