1

当我尝试运行 Map reduce 算法的 Netbeans 应用程序时出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.apache.hadoop.mapred.JobConf.<clinit>(JobConf.java:349)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1121)
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:72)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:125)
at org.apache.hadoop.security.Groups.<init>(Groups.java:54)
at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:142)
at     
org.apache.hadoop.security.UserGroupInformation.initUGI(UserGroupInformation.java:243)
at 
org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation
.java:216)
at     
org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation
.java:207)
at   
org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroup
Information.java:286)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroup
Information.java:500)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroup   
Information.java:483)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:73)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:133)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:138)
at cloudex.CloudEx.main(CloudEx.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 19 more

你能告诉我如何摆脱它吗?我不知道它产生了什么

4

3 回答 3

2

您需要将 log4j jar 添加到您的类路径中。

于 2013-01-18T15:31:58.987 回答
1

如@smcg 所述,将 log4j 类添加到您的类路径中,或者如果您使用的是 maven,则将以下内容添加到您的项目 pom.xml 中。

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
于 2013-01-18T15:36:11.317 回答
0

在log4j下载 Apache log4j *.jar 文件。将外部 *.jar 文件导入您的项目。

于 2013-01-18T15:36:56.163 回答