以下是我的系统配置:Windows8.1,vmware v12,2 centOS VM。我已经在我的虚拟机上安装了 hadoop,一个作为主,另一个作为从属 1。服务在两个节点上都已正确启动并运行。
我想编译我的第一个mapreduce程序,字数教程:我正在尝试使用以下方法进行编译:
[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
知道为什么我会收到此错误吗?我认为没有问题... :(
根据文档,您可以执行以下操作(在我的系统上测试并工作)
-
export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar
-
$HADOOP_HOME/bin/hadoop com.sun.tools.javac.Main WordCount.java
最后使用 -
jar cf wc.jar WordCount*.class
链接到官方文档 这里