this page에있는 hadoop 예제를 수행 중이며 클래스를 찾을 수 없음 오류가 발생했습니다. 이클립스는 어떤 구문 오류도보고 있지 않으며 job.setMapperClass(TokenizerMapper.class)
에 인스턴스를 강조 표시하면 TokenizerMapper 클래스를 강조 표시합니다. 하위 클래스이거나 여기에서 뭔가를 간과하고 있기 때문에입니까? 내가 명령을 hadoop jar word.jar input output
(나는 이미 디렉터리 (args) 매개 변수가/user/[myuser]에 HDFS에서 상대 경로라는 것을 알았 기 때문에 주 Hadoop 노드에서 실행하고 있으므로 문제가되지 않습니다.)
Any . 당신은 당신의 명령 줄에서 jar 이름이 누락되었습니다. 감사하겠습니다 여기
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 {
Configuration configuration = null;
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) {
Configuration conf = new Configuration();
Job job;
conf.addResource(new Path("/work/hadoop/config","core-site.xml"));
conf.addResource(new Path("/work/hadoop/config","hdfs-site.xml"));
try {
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);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
arg [0]은 WordCount, arg [1]은 입력, arg [2]는 출력되도록합니다. 코드가 I/O 디렉토리? 출력 디렉토리 [stuff]/input이 이미 있습니다. "라는 오류가 나타납니다. – Bennett
아니요. [this] (http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/CommandsManual.html#jar) 디렉토리는 동일한 입력을 여러 번 실행했을 수도 있다는 것을 의미합니다. 이전 실행 출력 파일을 실행하거나 삭제할 때마다 출력 디렉토리를 변경하십시오. – SMA
오류가 발생하여 출력이 예상되는 곳 (arg [1])에서 입력을보고 있으므로 설명서가 말하는 내용에 위배된다는 것을 알 수 있습니다. – Bennett