2015-03-03 25 views
1
public static void main(String[] args) throws IOException, URISyntaxException 

{ 配置配置=新配置();我如何才能在與Java HDFS一個新的目錄?

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); 

} }

Thier在線程 「主要」 java.lang.NoClassDefFoundError異常 例外:組織/阿帕奇/公地/配置/配置 在org.apache.hadoop.metrics2。 lib.DefaultMetricsSystem(DefaultMetricsSystem.java:37) 在org.apache.hadoop.metrics2.lib.DefaultMetricsSystem(DefaultMetricsSystem.java:34) 在org.apache.hadoop.security.UgiInstrumentation.create(UgiInstrumentation.java。: 51) 在org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInforma (org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:237) at org。)。 apache.hadoop.security.KerberosName。(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(U serGroupInformation.java:468) 在org.apache.hadoop.fs.FileSystem $緩存$關鍵。(FileSystem.java:1519) 在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) 導致:java.lang.ClassNotFoundException:org.apache.commons.configuration.Configuration at java.net.URLClassLoader $ 1.run(URLClassLoader.java:366) at java.net.URLClassLoader $ 1。在java.net.URLClassLoader.findClass(URLClassLoader.java:354)012處運行(URLClassLoader.java:355) (位於java.security.AccessController.doPrivileged(本地方法) )在java.lang.ClassLoader.loadClass(ClassLoader.java:425) 在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) 在java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 17更多 移民是真的 有什麼問題? 任何幫助!

回答

2

對於您的問題,您必須添加公共配置-1.6.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); 

} } 

你必須在構建下面添加罐子名單路徑。

公地CLI-1.2.jar

公地集合-3.2.1。罐子

公地配置-1.6.jar

公地琅2.5.jar

共享記錄-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

的log4j-1.2.17.jar

Hadoop的hdfs.jar

這些在Hadoop中所有可用的罐子/ lib目錄如果它是cloudera文件夾。

相關問題