eclipse出現Exception in thread "main" java.lang.NoClassDefFoundError
昨天晚上在跑hadoop程式的時候,新建了一個工程然後不知怎麼地就一直出現Exception in thread "main" java.lang.NoClassDefFoundError
錯誤如下:
Exception in thread "main" java.lang.NoClassDefFoundError: WordCount/class
Caused by: java.lang.ClassNotFoundException: WordCount.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: WordCount.class. Program will exit.
一直搞不定啊,嘗試了很多的方法,包括:
1、修改CLASSPATH
2、修改PATH
3、在eclipse的Property-> Java Build Path -> Libraries -> Add External Jars,把tools.jat , dt.jar都加進去
都不行啊,都要嘗試重灌eclipse了,突然靈機一動,想起了這裡Run AS -> Run Configurations -> Main,如下圖:
把畫圈的".class"去掉就OK了。
下面就執行成功了:
13/07/21 10:28:58 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
13/07/21 10:28:58 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
13/07/21 10:28:58 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/07/21 10:28:58 INFO input.FileInputFormat: Total input paths to process : 1
13/07/21 10:29:03 INFO mapred.JobClient: Running job: job_local_0001
13/07/21 10:29:03 INFO input.FileInputFormat: Total input paths to process : 1
13/07/21 10:29:03 INFO mapred.MapTask: io.sort.mb = 100
13/07/21 10:29:05 INFO mapred.JobClient: map 0% reduce 0%
13/07/21 10:29:05 INFO mapred.MapTask: data buffer = 79691776/99614720
13/07/21 10:29:05 INFO mapred.MapTask: record buffer = 262144/327680
13/07/21 10:29:05 INFO mapred.MapTask: Starting flush of map output
13/07/21 10:29:05 INFO mapred.MapTask: Finished spill 0
13/07/21 10:29:05 INFO mapred.TaskRunner: Task:attempt_local_0001_m_000000_0 is done. And is in the process of commiting
13/07/21 10:29:05 INFO mapred.LocalJobRunner:
13/07/21 10:29:05 INFO mapred.TaskRunner: Task 'attempt_local_0001_m_000000_0' done.
13/07/21 10:29:05 INFO mapred.LocalJobRunner:
13/07/21 10:29:05 INFO mapred.Merger: Merging 1 sorted segments
13/07/21 10:29:05 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 34 bytes
13/07/21 10:29:05 INFO mapred.LocalJobRunner:
13/07/21 10:29:05 INFO mapred.TaskRunner: Task:attempt_local_0001_r_000000_0 is done. And is in the process of commiting
13/07/21 10:29:05 INFO mapred.LocalJobRunner:
13/07/21 10:29:05 INFO mapred.TaskRunner: Task attempt_local_0001_r_000000_0 is allowed to commit now
13/07/21 10:29:05 INFO output.FileOutputCommitter: Saved output of task 'attempt_local_0001_r_000000_0' to output
13/07/21 10:29:05 INFO mapred.LocalJobRunner: reduce > reduce
13/07/21 10:29:05 INFO mapred.TaskRunner: Task 'attempt_local_0001_r_000000_0' done.
13/07/21 10:29:06 INFO mapred.JobClient: map 100% reduce 100%
13/07/21 10:29:06 INFO mapred.JobClient: Job complete: job_local_0001
13/07/21 10:29:06 INFO mapred.JobClient: Counters: 12
13/07/21 10:29:06 INFO mapred.JobClient: FileSystemCounters
13/07/21 10:29:06 INFO mapred.JobClient: FILE_BYTES_READ=26254
13/07/21 10:29:06 INFO mapred.JobClient: FILE_BYTES_WRITTEN=53072
13/07/21 10:29:06 INFO mapred.JobClient: Map-Reduce Framework
13/07/21 10:29:06 INFO mapred.JobClient: Reduce input groups=4
13/07/21 10:29:06 INFO mapred.JobClient: Combine output records=4
13/07/21 10:29:06 INFO mapred.JobClient: Map input records=1
13/07/21 10:29:06 INFO mapred.JobClient: Reduce shuffle bytes=0
13/07/21 10:29:06 INFO mapred.JobClient: Reduce output records=4
13/07/21 10:29:06 INFO mapred.JobClient: Spilled Records=8
13/07/21 10:29:06 INFO mapred.JobClient: Map output bytes=54
13/07/21 10:29:06 INFO mapred.JobClient: Combine input records=9
13/07/21 10:29:06 INFO mapred.JobClient: Map output records=9
13/07/21 10:29:06 INFO mapred.JobClient: Reduce input records=4
一個bug真的是可以讓人瘋掉的。。。在解決一個Bug之前死都不知道是怎麼死的。。。
希望給遇到這個bug的同學們一點幫助。