Problem while executing hadoop code
I just started with Hadoop. I wrote a sample hadoop code as was written in the book. But still, during the time of execution exceptions arise. The snippet of what I get :
[harsh@geek hadoop-0.20.2]$ hadoop MaxTemperature input/ncdc/sample.txt output Exception in thread "main" java.lang.NoClassDefFoundError: MaxTemperature Caused by: java.lang.ClassNotFoundException: MaxTemperature at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: MaxTemperature. Program will exit.
What shall I do?
When you run a hadoop jar this is the command which you should run in the directory you put the jar in (e.g. /usr/lib/hadoop-0.20/bin )
- hadoop jar NAMEOFJAR.jar arg1 arg2 argN
from your question this could be how to run it (make the cd to hadoop directory for the version of hadoop your running)
- cp MaxTemperature.jar /usr/lib/hadoop-0.20/bin
- su hadoop
- cd /usr/lib/hadoop-0.20/bin
- hadoop jar MaxTemperature.jar input/ncdc/sample.txt output
Add the MaxTemperature class to your class path.
It always looks for the entry point which is the main class, the piece of code which sets your mapper and reducer class. If it cant find it, it throws classnotfound exception.
I experienced the same thing. I documented a step by step solution on http://digitallibraryworld.com/?p=256. Hope it helps someone
Did you put MaxTemperature in a package?
If so, say your MaxTemperature.class
file is in yourdir/bin/yourpackage/
. You need to do:
export HADOOP_CLASSPATH=yourdir/bin
hadoop yourpackage.MaxTemperature
For Map Reduce Execution first you need to create Jar file with the classes i.e. Mapper,Reducer,Driver class. Move to folder where jar file is located and execute
bin/hadoop Sample.jar SampleDriver InputFileName OutPutFileName
Try it. should Work with these flow.
精彩评论