내 하둡 버전은 다음과 같습니다 2.8.1지도 "클래스를 찾을 수 없습니다 예외"를 제공
나는 단어 수의 소스 코드가 같다
Apache Hadoop 2.8.0에있는 맵리 듀스 예제를 실행하려고 이하.
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);
}
}
는 I 위의 코드를 삽입하여 WordCount.java 파일을 생성 (아파치 하둡 2.8.0 예에서 제시된 동일). 나는 그것을 컴파일했다.
javac -cp $HADOOP_CLASSPATH /sharedFiles/WordCount.java
그런 다음 WordCount * .classes를 결합하여 wc.jar 파일을 만들었습니다.
jar cf /sharedFiles/wc.jar /sharedFiles/WordCount*.class
sharedFiles 폴더 안에 파일은 다음과 같습니다.
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
이 오류가 발생합니다.
"wordcount"드라이버 클래스가 각 폴더에 만들어지지 않은 것을 확인했습니다. 그 수업을 만들기 위해 내가 할 수있는 일이 있습니까? 이 자습서에서는 해당 파일을 만드는 추가 단계에 대해서는 언급하지 않았습니다.
감사합니다.
JAR을 만들었을 때 sharedFiles 폴더가 패키지라고 생각 했습니까? 'sharedFiles.WordCount'를 시도 했습니까? –
@ cricket_007 네, 효과가있었습니다. 이와 함께 패키지 이름을 WordCount, java 파일에도 추가해야했습니다. 명령 줄에서 WordCount.java의 전체 경로를 지정했기 때문에 왜 필요한지 이해할 수 없습니다. 그러나 그것은 나를 위해 트릭을했습니다. 고맙습니다! – Yash