[Hadoop] Problems when running simple examples

Environment: Cloudera Cent OS 6.2 (CDH 5.0).

When I run a FileSystemCat example, I found there is something that needed to be configured before you compile the .class file and run it on Hadoop.

1. Source file should be compiled to “.class” file to be run on Hadoop.

My source file is FileSystemCat.java. But when I run “javac FileSystemCat.java”, there is a lot of errors, such as the followings.

This is because we did not specify the classpath. We can use the following command to compile it.

For convenience, we can export the classpath, such as

 2. Adding the path to Hadoop configuration file.

When I run the program like the following:

There would be an error like:

We need to add the path to file hadoop-env.sh. The location of this file is “/etc/hadoop/conf” on my machine.

In this file, you need to export your path of the class file to HADOOP_CLASSPATH, like:

After that, you can run your program successfully.