tags:

views:

38

answers:

1

I have set up Hadoop on my laptop and ran the example program given in the installation guide successfully. But, I am not able to run a program.

rohit@renaissance1:~/hadoop/ch2$ 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.

The book said that we should set a Hadoop Classpath by writing

rohit@renaissance1:~/hadoop/ch2$ export HADOOP_CLASSPATH=build/classes

The main class is defined in MaxTemperature.java file that I am executing. How do we set the Hadoop Classpath? Do we have to do it for all program execution or only once? Where should I put the input folder. My code is at /home/rohit/hadoop/ch2 and my Hadoop installation is at /home/hadoop.

A: 

You should package your application into a JAR file, that's much easier and less error-prone than fiddling with classpath folders.

In your case, you must also compile the .java file. You said it's MaxTemparature.java, but there must also be a MaxTemperature.class before you can run it.

mhaller
The book I am referring did say that we should package the files in a jar file for easy distribution over a cluster. But, for simplicity they are using individual files at the start.
movingahead