0

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?

1
  • did you compile your code with a compiler (javac)? Commented Sep 28, 2010 at 22:17

6 Answers 6

0

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
Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.
0

Add the MaxTemperature class to your class path.

5 Comments

I tried it. It still didn't work. "set CLASSPATH=/home/harsh/hadoop/hadoop-0.20.2/MaxTemp.java "
or probably you asked me to do something else? because I am totally new to Hadoop as I mentioned in the post.
I was under the impression it would work much the same as the java classpath issues that resemble this problem, based on your tags.
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.
I am doing this through command line and i have been stuck for almost a day now with this.
0

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.

Comments

0

I experienced the same thing. I documented a step by step solution on http://digitallibraryworld.com/?p=256. Hope it helps someone

1 Comment

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.