hadoop错误之ClassNotFoundException(下)

 hadoop开发环境:window上eclipse+虚拟机的ubuntu13.04+hadoop-1.1.2+JDK1.7

在win7下运行hadoop-1.1.2 worldcount代码的时候出现下面的错误,折腾了差不多一天的时间,才明白导致http://www.cnblogs.com/kaizhangzhang/p/3494753.html这个错误的原因,一下是错误的完整信息:

eclipse显示:

13/12/28 15:44:00 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/12/28 15:44:00 INFO input.FileInputFormat: Total input paths to process : 1
13/12/28 15:44:00 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
13/12/28 15:44:00 WARN snappy.LoadSnappy: Snappy native library not loaded
13/12/28 15:44:00 INFO mapred.JobClient: Running job: job_201312281229_0013
13/12/28 15:44:01 INFO mapred.JobClient:  map 0% reduce 0%
13/12/28 15:44:07 INFO mapred.JobClient: Task Id : attempt_201312281229_0013_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.kai.hadoop.MyMapreduce$MyMap
 at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:849)
 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:1149)
 at org.apache.hadoop.mapred.Child.main(Child.java:249)

查看了job的输出日志,显示错误:

java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.kai.hadoop.WordCount$TokenizerMapper at
org.apache.hadoop.conf.Configuration.getClass(Configuration.java:849) 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:1149)
at org.apache.hadoop.mapred.Child.main(Child.java:249) Caused by:
java.lang.ClassNotFoundException: com.kai.hadoop.WordCount$TokenizerMapper 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:802) at
org.apache.hadoop.conf.Configuration.getClass(Configuration.java:847) ... 8 more

我把这个WorldCount程序打成jar包在ubuntu上是可以正常运行,由于自己个人非常懒,是在不想换开发平台,依然坚持在windows上开发,在网上找了种种方案,最后终于解决了,网上说的也含含糊糊的,东平西凑的理解在一起总结:

  1、网上好多说要设置这job.setJarByClass(WordCount.class);但是hadoop-1.1.2的worldcount源码是有job.setJarByClass(WordCount.class);我们找到conf所在的位置,加conf.set("mapred.jar", "C:\\Users\\win7\\Desktop\\mapreduce.jar");  注意:"mapred.jar"不能改,后面是你导出jar的路径

  2、把工程打成xx.jar就是上面的mapreduce.jar,(右击工程->选择Export->选择要输出的package),我放在"C:\\Users\\win7\\Desktop",一般最好放工程里面,默认路径下

最后运行就可以了,然后就可以正常运行了,哈哈....虽然还是有点麻烦,要打jar包还要每次设置conf.set(),但是至少目前不用换环境了,比起每次上传到ubuntu再运行方便了一点点,对于初学的我来说已经是很好的开始,我觉得自己肯定是哪还没有配置好,应该还可以继续改进,继续研究...希望有知道的大神留下宝贵的意见!!

你可能感兴趣的:(hadoop错误之ClassNotFoundException(下))