我正在尝试运行 Hadoop wordcount 作业(我使用的是 hadoop 2.6.0)。当我将我的项目导出到可运行的 jar 并从 CLI 运行它时,它就可以工作了。但是,当我在 Eclipse 中使用“作为 Java 应用程序运行”启动它时,我收到以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.hadoop.conf.Configuration.(Configuration.java:173) at WordCount.main(WordCount.java:54) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory 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) ... 2 more
谁能帮我解决这个问题?
最佳答案
我认为您没有正确配置 Eclipse,它不知道在哪里可以找到 Apache Commons 库 jar。来自 this tutorial ,您可能错过了最后的步骤:
To run tests from Eclipse you need to additionally do the following:
- Under project Properties, select Java Build Path, and the Libraries tab
- Click "Add External Class Folder" and select the build directory of the current project
您可能还想看看 this other tutorial它显示了如何/在何处添加依赖项 jar 以运行 Hadoop 程序。
关于java - 在 Eclipse 中运行 hadoop 作业时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32011026/