マイHadoopのバージョンを与える削減です:2.8.1地図ワードカウントプログラムは、「クラスが見つからない例外」
WORDCOUNTソースコードであるMapReduceの例を実行しようとしていますようです以下私は上記のコードを挿入することによってWordCount.javaファイルを作成
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context) throws IOException,
InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
(ApacheのHadoopの2.8.0の例に示されたのと同じ)。 それから私はそれを集めました。
javac -cp $HADOOP_CLASSPATH /sharedFiles/WordCount.java
次に、WordCount * .classesを組み合わせてwc.jarファイルを作成しました。
jar cf /sharedFiles/wc.jar /sharedFiles/WordCount*.class
ファイルは次のようになります。
ls /sharedFiles
history wc.jar WordCount.class
WordCount$IntSumReducer.class
WordCount.java WordCount$TokenizerMapper.class
次に、mapreduceコマンドを実行しようとしました。
hadoop jar /sharedFiles/wc.jar wordcount /sharedFiles/history /sharedFiles /output
このエラーが発生します。
Exception in thread "main" java.lang.ClassNotFoundException: wordcount
ドライバクラス "wordcount"がそれぞれのフォルダに作成されていないことに気付きました。そのクラスを作るためにできることはありますか?このチュートリアルでは、そのファイルを作成するための追加ステップについては触れていません。
ありがとうございます。
JARを作成したときに、sharedFilesフォルダがパッケージであると思われましたか?あなたは 'sharedFiles.WordCount'を試しましたか? –
@ cricket_007はい、うまくいきました。それと並行して、パッケージ名もWordCount、javaファイルに追加する必要がありました。コマンドラインでWordCount.javaの完全なパスを指定するので、私はなぜそれが必要なのか分かりません。 しかし、それは私のためのトリックでした。ありがとうございました! – Yash