aa8y
aa8y

Reputation: 3942

Unable to read HDFS using Java program: Could not find or load main class

I am trying to cat a file stored in the HDFS. I tried the methods provided under both the headings, Reading Data from a Hadoop URL and Reading Data Using the FileSystem API of the book Hadoop: The Definitive Guide but I keep getting the error:

Error: Could not find or load main class <class_name>

Can someone point out what I am doing wrong?

Upvotes: 0

Views: 1807

Answers (2)

Kishore Bhosale
Kishore Bhosale

Reputation: 569

step 1: Compile Java Program:

javac URLCat.java -classpath $HADOOP_HOME/share/hadoop/common/hadoop-common-2.7.0.jar

step 2: Create jar file :

jar cvf URLCat.jar URLCat.class

Step 3: Execute program : (mention your hdfs file location)

hadoop jar URLCat.jar URLCat hdfs://localhost:9000/pcode/wcinput.txt

Upvotes: 1

shazin
shazin

Reputation: 21883

I can't see all the pages in the link, but I think I know what's going on. You are trying to run the commands like this.

% hadoop URLCat <HDFS URL>

The error you are getting is related to Hadoop being not able to find the class URLCat in its classpath. You can either edit the hadoop command file to include URLCat in its classpath. This is not advised though.

What is best is to create a jar file with the URLCat class inside and call that with the following command

% hadoop jar <Path to Jar>/<Your Jar>.jar URLCat <HDFS URL>

Read this blog post for more information which shows how to run a jar.

Upvotes: 0

Related Questions