hadoop运行编写的wordcount程序时抛出ClassNotFoundException异常

1. wordcount源程序结构为: 

hadoop运行编写的wordcount程序时抛出ClassNotFoundException异常_第1张图片

2. 将wordcount的源程序打包乘wordcount.jar过程如下:

3. hadoop运行打包好的jar文件,执行下面命令,出现异常:

[hadoop01@hadoop01 export]$ hadoop jar wordcount.jar wordcount /user/hadoop/input/file* /user/hadoop/output
Exception in thread "main" java.lang.ClassNotFoundException: wordcount
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:219)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:141)

 4. 解决办法

出现问题的原因是受到了官方示例wordcount的影响:

[hadoop01@hadoop01 hadoop-2.7.7]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount /user/hadoop/input/file* /user/hadoop/output

应该把wordcount改为wordcount.jar中主类的绝对路径com.skp.wordcount.WordMain,命令如下:

[hadoop01@hadoop01 export]$ hadoop jar wordcount.jar com.skp.wordcount.WordMain /user/hadoop/input/file* /user/hadoop/output

运行结果如下:

hadoop运行编写的wordcount程序时抛出ClassNotFoundException异常_第2张图片

 hadoop运行编写的wordcount程序时抛出ClassNotFoundException异常_第3张图片

 参考文章:

Exception in thread "main" java.lang.ClassNotFoundException:

你可能感兴趣的:(笔记)