2011-09-26 53 views
3

我想讀取SequenceFile自定義Writeable在裏面。當讀取hadoop時java.lang.NoClassDefFoundError SequenceFile

下面的代碼:

public static void main(String[] args) throws IOException { 
    //String iFile = null; 
    String uri = "/tmp/part-r-00000"; 
    Configuration conf = new Configuration(); 
    FileSystem fs = FileSystem.get(URI.create(uri), conf); 
    Path path = new Path(uri); 
    MyClass value = new MyClass(); 
    SequenceFile.Reader reader = null; 
    try { 
     reader = new Reader(fs, path, conf); 
     while(reader.next(value)){ 
      System.out.println(value.getUrl()); 
      System.out.println(value.getHeader()); 
      System.out.println(value.getImages().size());    
      break; 
     }   

    } catch (Exception e) {// Catch exception if any 
     System.err.println("Error: " + e.getMessage()); 
    } 
    finally { 
     IOUtils.closeStream(reader); 
    } 

} 

當我運行它,我得到以下異常:

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:196) 
    at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:159) 
    at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:216) 
    at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:409) 
    at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:395) 
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:1418) 
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1319) 
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:226) 
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:109) 
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:210) 
    at com.iathao.run.site.emr.DecryptMapReduceOutput.main(DecryptMapReduceOutput.java:32) 
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266) 
    ... 14 more 

所有庫被打包成jar文件和存在。怎麼了,我該如何解決這個問題?

+1

如果你打開lib的jar,你可以找到這個類? org/apache/commons/configuration /配置 如何生成你的jar? –

+0

hadoop jar不在類路徑中。你如何運行? –

+0

明白了。我需要以下庫:http://www.java2s.com/Code/Jar/ABC/Downloadcommonsconfigurationjar.htm,以使程序正常運行。雖然這很奇怪。 –

回答

4

對於org.apache.commons.configuration.Configuration類,必須包含hadoop-common - *。jar。把jar作爲依賴關係。

相關問題