Java 设置类路径后包 org.apache.hadoop.conf 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24390492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:55:44  来源:igfitidea点击:

package org.apache.hadoop.conf does not exist after setting classpath

javahadoopjavacword-counthadoop-plugins

提问by user3287477

I am a beginner in hadoop using the hadoop's beginners guide book as a tutorial.

我是 hadoop 的初学者,使用 hadoop 的初学者指南作为教程。

I am using a mac osx 10.9.2 and hadoop version 1.2.1

我使用的是 mac osx 10.9.2 和 hadoop 版本 1.2.1

I have set all the appropriate class path, when I call echo $PATH in terminal:

当我在终端中调用 echo $PATH 时,我已经设置了所有适当的类路径:

Here is the result I get:

这是我得到的结果:

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/oladotunopasina/hadoop-1.2.1/hadoop-core-1.2.1.jar:/Users/oladotunopasina/hadoop-1.2.1/bin:/usr/share/grails/bin:/usr/share/groovy/bin:/Users/oladotunopasina/.rvm/gems/ruby-2.1.1/bin:/Users/oladotunopasina/.rvm/gems/ruby-2.1.1@global/bin:/Users/oladotunopasina/.rvm/rubies/ruby-2.1.1/bin:/usr/local/heroku/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/oladotunopasina/.rvm/bin:/Users/oladotunopasina/.rvm/bin

/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/oladotunopasina/hadoop-1.2.1/hadoop-core-1.2.1.jar:/Users/oladotunopasina/hadoop-1.2.1/bin:/ usr/share/grails/bin:/usr/share/groovy/bin:/Users/oladotunopasina/.rvm/gems/ruby-2.1.1/bin:/Users/oladotunopasina/.rvm/gems/ruby-2.1.1 @global/bin:/Users/oladotunopasina/.rvm/rubies/ruby-2.1.1/bin:/usr/local/heroku/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr /local/bin:/Users/oladotunopasina/.rvm/bin:/Users/oladotunopasina/.rvm/bin

I tried compiling WordCount1.java and I am getting the following error:

我尝试编译 WordCount1.java,但出现以下错误:

WordCount1.java:2: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configuration ;
                         ^
WordCount1.java:3: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                       ^
WordCount1.java:4: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.IntWritable;
                       ^
WordCount1.java:5: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
                       ^
WordCount1.java:6: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Job;
                              ^
WordCount1.java:7: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Mapper;
                              ^

Kindly help.

请帮忙。

采纳答案by donut

The CLASSPATH variable is the way to tell applications, including the JDK tools(javac), where to look for user classes.

CLASSPATH 变量是告诉应用程序(包括 JDK 工具 (javac))到何处查找用户类的方式。

You can set this variable as given below and try compiling the class.

您可以按如下所示设置此变量并尝试编译该类。

export CLASSPATH=$CLASSPATH:/Users/oladotunopasina/hadoop-1.2.1/hadoop-core-1.2.1.jar

回答by eliasah

If you are using a build tools such as Maven, Gradle, sbt, etc.

如果您使用的是构建工具,例如 Maven、Gradle、sbt 等。

You have to add the dependency plugin to your build file.

您必须将依赖项插件添加到您的构建文件中。

For Maven,per example, you have to add the following into your pom.xml

对于 Maven,每个示例,您必须将以下内容添加到您的 pom.xml

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>1.2.1</version>
</dependency>

You can find the dependency settings for other build tools here

您可以在此处找到其他构建工具的依赖项设置