如何定义HADOOP类路径?

时间:2019-07-11 14:50:40

标签: java hadoop

这段代码来自Hadoop和Spark课程。我正在VM(HDP-沙盒)上运行它

[root@sandbox-hdp Lesson-5.3_hadoop-grep]# javac -classpath /usr/lib/hadoop/hadoop-core.jar -d Grep_classes Grep.java
Grep.java:22: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configuration;
                             ^
Grep.java:23: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configured;
                             ^
Grep.java:24: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.FileSystem;
                           ^
Grep.java:25: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;

我是Hadoop新手,如何定义类路径?

如果我尝试

hadoop classpath

输出

/usr/hdp/3.0.1.0-187/hadoop/conf:/usr/hdp/3.0.1.0-187/hadoop/lib/*:/usr/hdp/3.0.1.0-187/hadoop/.//*:/usr/hdp/3.0.1.0-187/hadoop-hdfs/./:/usr/hdp/3.0.1.0-187/hadoop-hdfs/lib/*:/usr/hdp/3.0.1.0-187/hadoop-hdfs/.//*:/usr/hdp/3.0.1.0-187/hadoop-mapreduce/lib/*:/usr/hdp/3.0.1.0-187/hadoop-mapreduce/.//*:/usr/hdp/3.0.1.0-187/hadoop-yarn/./:/usr/hdp/3.0.1.0-187/hadoop-yarn/lib/*:/usr/hdp/3.0.1.0-187/hadoop-yarn/.//*:/usr/hdp/3.0.1.0-187/tez/*:/usr/hdp/3.0.1.0-187/tez/lib/*:/usr/hdp/3.0.1.0-187/tez/conf:/usr/hdp/3.0.1.0-187/tez/conf_llap:/usr/hdp/3.0.1.0-187/tez/doc:/usr/hdp/3.0.1.0-187/tez/hadoop-shim-0.9.1.3.0.1.0-187.jar:/usr/hdp/3.0.1.0-187/tez/hadoop-shim-2.8-0.9.1.3.0.1.0-187.jar

如何更改javac行?

1 个答案:

答案 0 :(得分:0)

您可以在 hadoop-env.sh 中导出HADOOP_CLASSPATH。您可以向HADOOP_CLASSPATH添加更多jar。

稍后在运行作业之前,请在shell中运行以下命令。

export HADOOP_CLASSPATH=$(hadoop classpath)
echo $HADOOP_CLASSPATH

For reference see this enter image description here