hadoop作业返回异常“classnotfound”

fhg3lkii  于 2021-05-27  发布在  Hadoop
关注(0)|答案(1)|浏览(418)

我正在尝试在hadoop上启动一个单词计数Mapreduce。当我让hadoop做这项工作时,它会返回以下内容:

Exception in thread "main" java.lang.ClassNotFoundException: sdz.hadoop.wordcount.WordCountDriver
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:398)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:232)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:153)

这是输出:

hadoop jar wordcount.jar sdz.hadoop.wordcount.WordCountDriver ../source.txt ../results

jar文件如下所示:

$jar tf wordcount.jar 
META-INF/
META-INF/MANIFEST.MF
WordCountReducer.class
WordCountMapper.class
WordCountDriver.class

jar文件已使用以下命令/输出生成:

$jar -cvf wordcount.jar .
added manifest
adding: WordCountReducer.class(in = 1720) (out= 723)(deflated 57%)
adding: WordCountMapper.class(in = 2347) (out= 936)(deflated 60%)
adding: WordCountDriver.class(in = 2278) (out= 1118)(deflated 50%)

这些类是通过以下命令生成的:

javac -classpath $HADOOP_CLASSPATH WordCount*.java

java文件包含(我知道无用的导入):
wordcountreducer.java语言
wordcountmapper.java语言
wordcountdriver.java语言
其他关于这个的问题说要添加“job.setjarbyclass(wordcountdriver.class);”。但我已经有了。那我犯了什么错?

qxgroojn

qxgroojn1#

作业将失败,因为它尝试(并且失败)在jar中的以下位置找到您的类:

sdz/hadoop/wordcount/WordCountDriver.class

最快的解决方案是从run命令(以及类本身中的任何包声明)中删除包名:

hadoop jar wordcount.jar WordCountDriver ../source.txt ../results

一个更稳定的解决方案是使用maven或gradle这样的构建工具正确地构建jar。

相关问题