tags:

views:

45

answers:

2

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?

A: 

Add the MaxTemperature class to your class path.

Woot4Moo
I tried it. It still didn't work. "set CLASSPATH=/home/harsh/hadoop/hadoop-0.20.2/MaxTemp.java "
Harsh
or probably you asked me to do something else? because I am totally new to Hadoop as I mentioned in the post.
Harsh
I was under the impression it would work much the same as the java classpath issues that resemble this problem, based on your tags.
Woot4Moo
my bad! the book also says about setting classpath. "export HADOOP_CLASSPATH=build/classes" I did even this but still I get the same error.
Harsh
are you doing this through an ide or on the command line?
Woot4Moo
I am doing this through command line and i have been stuck for almost a day now with this.
Harsh
A: 

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
Joe Stein
does that mean that I have to create a jar file for my code? the book also said this but it was written in the way as if it were just an option. and if I have to, how do I make one?
Harsh
you do have to make a jar file. if you're using eclipse, there's an option for it. a tutorial shouldn't be hard to find.
coffeepac