编译Hadoop wordcount教程 - hadoop 2.6.3

时间:2016-01-24 12:28:13

标签: java hadoop

以下是我的系统配置:windows8.1,vmware v12,2 centOS VM。我在我的VM上安装了hadoop,一个作为master,另一个作为slave1。这些服务在两个节点上都正确启动并运行。

我想编译我的第一个mapreduce程序,wordcount教程: 我尝试使用以下内容进行编译:

[hadoop@master ~]$ javac -classpath $HADOOP_HOME/share/common/hadoop-common-2.6.3.jar:$HADOOP-HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.3.jar:$HADOOP_HOME/share/common/lib/common-cli-1.2.jar -d /home/hadoop *.java

但我得到的答案是:

WordCount.java:4: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configuration;
                             ^
WordCount.java:5: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                           ^
WordCount.java:6: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.IntWritable;
                           ^
WordCount.java:7: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
                           ^
WordCount.java:8: error: package org.apache.hadoop.mapreduce does not exist
(.
.
.)                                       ^
  symbol:   class Path
  location: class WordCount
WordCount.java:58: error: cannot find symbol
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    ^
  symbol:   variable FileOutputFormat
  location: class WordCount
40 errors

我用谷歌搜索,每个人都说是因为$ CLASSPATH。

这是我的/ etc / bashrc文件:

export JAVA_HOME=/opt/jdk
export JRE_HOME=/opt/jdk/jre
export PATH=$PATH:/opt/jdk/bin:/opt/jdk/jre/bin
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/opt/hadoop/
export CLASSPATH=$CLASSPATH:$HADOOP_HOME/share/common/hadoop-common-2.6.3.jar:$HADOOP-HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.3.jar:$HADOOP_HOME/share/common/lib/common-cli-1.2.jar

任何想法为什么我得到这个错误?我觉得没问题...... :(

1 个答案:

答案 0 :(得分:0)

根据文档,您可以执行以下操作(在我的系统上测试并运行)

  • sc.nextLine(); String sWordToChange = sc.nextLine(); int index=-1; for (int i = 0; i < sEnterWord.length; i++) { if(sEnterWord[i].equals(sWordToChange)) index=i; }
  • export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar 最后使用
  • 创建jar
  • $HADOOP_HOME/bin/hadoop com.sun.tools.javac.Main WordCount.java

link to the official doc here