无法将java文件编译为hadoop的类文件

时间:2016-03-10 23:34:49

标签: java hadoop hadoop2

我正在使用hadoop 2.6.4并尝试使用以下命令编译java文件:

javac -classpath $HADOOP_HOME/share/hadoop/common/hadoop-common-2.6.4.jar:$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.4.jar:$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar -d class_files *.java

但由于缺少hadoop包,这不是编译文件:

GraphSearch.java:28: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configured;
                         ^
GraphSearch.java:29: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                       ^
GraphSearch.java:30: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.IntWritable;
                       ^
GraphSearch.java:31: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.LongWritable;
                       ^
GraphSearch.java:32: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
                       ^
GraphSearch.java:33: error: package org.apache.hadoop.mapred does not exist
import org.apache.hadoop.mapred.*;
^
GraphSearch.java:34: error: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.Tool;
                         ^
GraphSearch.java:35: error: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.ToolRunner;
                         ^
GraphSearch.java:52: error: cannot find symbol
public class GraphSearch extends Configured implements Tool {

尝试使用以下命令设置类路径,不确定它是否正确:

export CLASSPATH=$CLASSPATH:/usr/local/hadoop/share/hadoop/common/hadoop-common-2.6.4.jar:$/usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.4.jar:/usr/local/hadoop/share/hadoop/common/lib/commons-cli-1.2.jar

请帮忙!

2 个答案:

答案 0 :(得分:1)

试试这个:

export PATH=$PATH:$HADOOP_HOME/bin

javac -cp $(hadoop classpath) -d class_files *.java

短而甜,但请确保您已设置HADOOP_HOME env变量。

答案 1 :(得分:0)

这是因为hadoop jar文件中缺少类。 从这里下载jar文件: Hadoop pre built jar

在core / build / libs文件夹中替换它