2016-09-25 78 views
0

我試圖運行WordCount example。但是我正在編譯程序時遇到問題。無法執行基本的Hadoop Mapreduce Wordcount示例

我得到的錯誤:

error: package org.apache.hadoop.mapred does not exist

執行後:

javac -classpath /usr/local/hadoop/share/hadoop/common/hadoop-common-2.7.3.jar -d wordcount_classes WordCount.java 

我成立了Hadoop的使用這個tutorial我也看了這個在stackoverflowquestion並在/usr/local/hadoop執行bin/hadoop classpath命令。這是我得到的輸出:

/usr/local/hadoop/etc/hadoop:/usr/local/hadoop/share/hadoop/common/lib/* :/usr/local/hadoop/share/hadoop/common/* :/usr/local/hadoop/share/hadoop/hdfs:/usr/local/hadoop/share/hadoop/hdfs/lib/* :/usr/local/hadoop/share/hadoop/hdfs/* :/usr/local/hadoop/share/hadoop/yarn/lib/* :/usr/local/hadoop/share/hadoop/yarn/* :/usr/local/hadoop/share/hadoop/mapreduce/lib/* :/usr/local/hadoop/share/hadoop/mapreduce/* :/contrib/capacity-scheduler/*.jar

但我不知道該怎麼做,或者我的下一步應該是什麼!請幫忙!

回答

2

您正在嘗試使用衆多hadoop依賴關係jar(hadoop-common-x.x.x.jar)之一來編譯源代碼。包含錯誤消息中記錄的mapred軟件包的jar是hadoop-mapreduce-client-core jar。

我建議你使用諸如Maven或Gradle等構建工具來構建源代碼,因爲它會爲你管理傳遞依賴。

或者繼續與你的javac手動調用,嘗試這樣的事情(未經測試):

javac -cp '/usr/local/hadoop/share/hadoop/common/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/hdfs/lib/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/hdfs/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/yarn/lib/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/yarn/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/mapreduce/lib/*' \ 
    -cp '/usr/local/hadoop/share/hadoop/mapreduce/*' \ 
    -d wordcount_classes WordCount.java