本文之所以称之为经验,是因为我们经常碰到莫名其妙的问题,从原理上是说不通的。但是我们却确确实实碰到了。
在刚开始运行的时候,碰到了下文所表示的错误。本想作为经验总结留下来。为了让错误重现,所以又重新操作了一遍。这时候已经换环境,但是环境与原先没做任何的更改,也就是说他们的配置完全是一样的,神奇的是mapreduce执行的完全正确。对于如果碰到下面问题的同学,可以参考。对于原理性的内容,以后在更新。
对于新手,经常遇到,在eclipse中是可以运行的,但是打包放到集群上,不可行,问题如下:
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
- at mapreduce.mapreduce.main(mapreduce.java:24)
- Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
- 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)
- ... 1 more
- hadoop jar '/home/user/Desktop/mapreduce.jar' mapreduce
- 14/03/05 05:35:09 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
- 14/03/05 05:35:09 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
- 14/03/05 05:35:09 INFO input.FileInputFormat: Total input paths to process : 1
- 14/03/05 05:35:09 INFO util.NativeCodeLoader: Loaded the native-hadoop library
- 14/03/05 05:35:10 WARN snappy.LoadSnappy: Snappy native library not loaded
- 14/03/05 05:35:10 INFO mapred.JobClient: Running job: job_201402280238_0011
- 14/03/05 05:35:11 INFO mapred.JobClient: map 0% reduce 0%
- 14/03/05 05:35:25 INFO mapred.JobClient: Task Id : attempt_201402280238_0011_m_000000_0, Status : FAILED
- java.lang.RuntimeException: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
- at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
- at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
- at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
- at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
- at java.security.AccessController.doPrivileged(Native Method)
- at javax.security.auth.Subject.doAs(Subject.java:415)
- at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
- at org.apache.hadoop.mapred.Child.main(Child.java:249)
- Caused by: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- 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)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:270)
- at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:820)
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:865)
- ... 8 more
- 14/03/05 05:35:31 INFO mapred.JobClient: Task Id : attempt_201402280238_0011_m_000000_1, Status : FAILED
- java.lang.RuntimeException: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
- at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
- at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
- at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
- at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
- at java.security.AccessController.doPrivileged(Native Method)
- at javax.security.auth.Subject.doAs(Subject.java:415)
- at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
- at org.apache.hadoop.mapred.Child.main(Child.java:249)
- Caused by: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- 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)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:270)
- at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:820)
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:865)
- ... 8 more
- 14/03/05 05:35:37 INFO mapred.JobClient: Task Id : attempt_201402280238_0011_m_000000_2, Status : FAILED
- java.lang.RuntimeException: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
- at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
- at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
- at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
- at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
- at java.security.AccessController.doPrivileged(Native Method)
- at javax.security.auth.Subject.doAs(Subject.java:415)
- at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
- at org.apache.hadoop.mapred.Child.main(Child.java:249)
- Caused by: java.lang.ClassNotFoundException: mapreduce.mapreduce$MyMapper
- 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)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:270)
- at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:820)
- at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:865)
- ... 8 more
- 14/03/05 05:35:49 INFO mapred.JobClient: Job complete: job_201402280238_0011
- 14/03/05 05:35:49 INFO mapred.JobClient: Counters: 7
- 14/03/05 05:35:49 INFO mapred.JobClient: Job Counters
- 14/03/05 05:35:49 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=33927
- 14/03/05 05:35:49 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=0
- 14/03/05 05:35:49 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=0
- 14/03/05 05:35:49 INFO mapred.JobClient: Launched map tasks=4
- 14/03/05 05:35:49 INFO mapred.JobClient: Data-local map tasks=4
- 14/03/05 05:35:49 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=0
- 14/03/05 05:35:49 INFO mapred.JobClient: Failed map tasks=1
我们需要分析上面是什么错误,其实就是找不到类,为什么会找不到类,是我们打包问题吗?是因为没有环境不正确吗?
是的,这两方面可能都有问题,那么该如何解决
首先来看看我们是如何打包的:
1.单击map.java文件,弹出快捷菜单,选择Export。
2.第一步之后,我们会看到下面,选择Java下面的JAR file。
3.我们单击Next,进入JAR Export选择我们要打的包即可。
4.单击next下一步,然后在下一步,咱们会看到主类,我们选择主类到Main class
5.选择主类到Main class,我们会看到mapreduce.map,其实这是 包名.类型
6.到这一步,单击finish。我们看到了这个包。并且看到它的大小。
打包完毕,我们放到集群上运行:
出现下面情况
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
。
解决:
对于上面我们是否可以采用另外一种方法:答案是可以的。
就是我们,打成java运行jar包,是绝对可行的。
我们打完包之后,我们会看到,运行包与前面包进行对比,一个K级别,一个是M级别。
总结:
对于上面产生的问题,通用的方法就是我们可以打包成运行包,在集群上运行是没有问题的。打成运行包,是我们把程序中相关的包都打进运行包中,虽然有点冗余,可以解决初学者面临的这个问题。
但是不适用开发环境和运行环境,版本不一致的情况
http://www.aboutyun.com/thread-7086-1-1.html