0

I am trying to run a java class in Hadoop, just like in the book "Hadoop.The.Definitive.Guide", like this:

hadoop URLCat hdfs://localhost/user/hamza/sometext.txt

Where it is supposed to print the contents of sometext.txt to the terminal. What happens is when I type that command it gives me this error:

Error: Could not find or load main class URLCat

URLCat is a Java class, but I have no idea why it's not working. I tried converting it to a jar file using IntelliJ but then when I run it, like this:

hadoop jar Hadoop_example.jar URLCat hdfs://localhost/user/hamza/sometext.txt

Note: Hadoop_example.jar is the jar file name and the class that has main method is URLCat.

It gives me this error:

Exception in thread "main" java.lang.ClassNotFoundException: URLCat
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

So how can I run Java classes in Hadoop. I found a similar question on Stack overflow but the answers were mostly to convert it into a jar file, but that didn't work for me either.

1 Answers1

0
hadoop jar Hadoop_example.jar URLCat hdfs://localhost/user/hamza/sometext.txt

This is the correct command line to start a program on hadoop. Why it does not start depends on how you made the jar.

This POST will be useful to you.

Community
  • 1
  • 1
ozw1z5rd
  • 3,034
  • 3
  • 32
  • 49