0

I'm trying to compile a java file which is importing hadoop packages.

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

But it fails with a message

error: package org.apache.hadoop.fs does not exist

I googled for this error and it seems that I have to edit $PATH

But I have no idea to what I have to fix the path.

How can I solve this import error?

yoon
  • 1,177
  • 2
  • 15
  • 28
  • 3
    Have you added hadoop library to your classpath? Which dependency management tool are you using - maven, gradle, or any other? – Smile Feb 18 '20 at 09:44
  • I think you don't have hadoop's jar files. Did you add them to your application? Is your project a Maven project or not? – A. Wolf Feb 18 '20 at 09:45
  • Are you using an IDE? It'll clearly highlight errors before you compile yourself – OneCricketeer Feb 18 '20 at 10:26
  • @Smile Could you tell me the way to add hadoop library? I just started with a book, and am very new to this kind of work. – yoon Feb 18 '20 at 10:32
  • If you are not using any dependency management tools, you might want to check out https://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project – Smile Feb 18 '20 at 10:38
  • @Smile I compiled with the following command: javac -cp ~/PATH/hadoop-common-2.7.1.jar filename.java and errors for importing org.apache.hadoop.fs and etc are gone. But importing org.apache.hadoop.mapreduce.blahblah still cause errors. Did I added a wrong file? – yoon Feb 18 '20 at 11:07

1 Answers1

0

You have bad import, its

import org.apache.hadoop.fs.Path;

Not

import org.apahce.hadoop.fs.Path;

The other posibility its you have bad import, can show how import the library of hadoop.

Adrian Lagartera
  • 442
  • 1
  • 3
  • 17
  • Sorry, it was a typo only for here.. My code is written correctly. – yoon Feb 18 '20 at 10:27
  • Ok, you are using Maven, Only Java, or another way to import the librarie, if you can add an image or your classpath. How import the library. The problem only succes when you run your program? @yoon – Adrian Lagartera Feb 18 '20 at 10:30