hadoop类notfoundexception

ejk8hzay  于 2021-06-04  发布在  Hadoop
关注(0)|答案(3)|浏览(365)

我正在写我的第一个hadoop应用程序,我得到了一个错误。我不太明白这个堆栈跟踪中的一些细节是什么意思。它是一个 ClassNotFoundException . 我在ubuntulinuxv12.10、eclipse3.8.0、java1.6.0\u24上构建它。我通过从apache站点下载hadoop并用ant构建它来安装hadoop。
当我创造一份工作时,我的崩溃是在程序的第一行。

public static void main(String[] args) throws IOException, InterruptedException,  ClassNotFoundException {

    Job job = new Job(); <<== crashing here.

Program [Java Application]  
com.sandbox.hadoop.Program at localhost:33878   
    Thread [main] (Suspended (exception ClassNotFoundException))    
        owns: Launcher$AppClassLoader  (id=29)  
        owns: Class<T> (org.apache.hadoop.security.UserGroupInformation) (id=25)    
        URLClassLoader$1.run() line: 217    
        AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]   
        Launcher$AppClassLoader(URLClassLoader).findClass(String) line: 205 
        Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: 321   
        Launcher$AppClassLoader.loadClass(String, boolean) line: 294    
        Launcher$AppClassLoader(ClassLoader).loadClass(String) line: 266    
        DefaultMetricsSystem.<init>() line: 37  
        DefaultMetricsSystem.<clinit>() line: 34    
        UgiInstrumentation.create(Configuration) line: 51   
        UserGroupInformation.initialize(Configuration) line: 216    
        UserGroupInformation.ensureInitialized() line: 184  
        UserGroupInformation.isSecurityEnabled() line: 236  
        KerberosName.<clinit>() line: 79    
        UserGroupInformation.initialize(Configuration) line: 209    
        UserGroupInformation.ensureInitialized() line: 184  
        UserGroupInformation.isSecurityEnabled() line: 236  
        UserGroupInformation.getLoginUser() line: 477   
        UserGroupInformation.getCurrentUser() line: 463 
        Job(JobContext).<init>(Configuration, JobID) line: 80   
        Job.<init>(Configuration) line: 50  
        Job.<init>() line: 46   
        Program.main(String[]) line: 17 
/usr/lib/jvm/java-6-openjdk-amd64/bin/java (Jan 14, 2013 2:42:36 PM)

控制台输出:

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:216)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.KerberosName.<clinit>(KerberosName.java:79)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:209)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:184)
at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:236)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:477)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:463)
at org.apache.hadoop.mapreduce.JobContext.<init>(JobContext.java:80)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:50)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:46)
at com.sandbox.hadoop.Program.main(Program.java:18)

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)
... 16 more
trnvg8h3

trnvg8h31#

我也面临同样的问题,我通过在构建路径中添加commons-configuration-x.x.jar来解决它,它位于$hadoop\u home/lib之下。

kiz8lqtg

kiz8lqtg2#

你的主程序需要吗 org.apache.commons.configuration.Configuration 还是应该这样 org.apache.hadoop.conf.Configuration ?
看起来eclipse自动导入了错误的配置类,当hadoop在集群上运行时,它不在类路径上。
你能分享你的源代码吗,特别是 com.sandbox.hadoop.Program 班级, main 方法?

plicqrtu

plicqrtu3#

你应该把所有的jar都加进去 /usr/lib/hadoop-0.xx/lib 以避免此类类路径问题。
为了给你一个主意,你可以打字 hadoop classpath 它将向您打印获取hadoopjar和所需库所需的类路径。
在你的情况下,你错过了 hadoop-common-0.xx.jar ,所以您应该将它添加到类路径中,这样就可以开始了。

相关问题