我写了一个小的MapReduce作业,它在单个文件中工作得很好。我现在需要做的是(对于一个类)从一个单独的类中驱动相同的MapReduce作业。我在下面对此进行解释。
什么有效:
public class Count {
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{
do mapping stuff
}
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
do reducing stuff
}
public static void main(String[] args) throws Exception {
runs the MR job perfectly!
}
我需要做什么:
// ===================== NB_train_hadoop.java =====================
public class NB_train_hadoop {
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{
do mapping stuff
}
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
do reducing stuff
}
// =========================== run.java ===========================
public class run {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Run NB Count");
// Job job = New Job(conf, "Run NB Count");
job.setJarByClass(NB_train_hadoop.class);
job.setMapperClass(NB_train_hadoop.TokenizerMapper.class);
job.setCombinerClass(NB_train_hadoop.IntSumReducer.class);
job.setReducerClass(NB_train_hadoop.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);
}
}
当我运行此程序时,我在线程"main"java.lang.NoClassDefFoundError:NB_train_hadoop$TokenizerMapper中得到一个异常在run.main(run.java:19)错误。这指向我的run.java中的setMapperClass行,但我不明白为什么要得到它。这些类应该对包中的任何其他类都可见。
如果有帮助的话,这就是我编译、jar和运行MR作业的方式。直到第三个命令出现错误。
>>> bin/hadoop com.sun.tools.javac.Main NB_train_hadoop.java run.java
>>> jar cvf run.jar run.class
>>> bin/hadoop jar run.jar run /user/nbcount/input /user/nbcount/output3
任何关于为什么会发生这种情况的建议都将非常棒!
您必须在主程序或驱动程序中指定主类或驱动程序类的包信息。您可以使用以下命令正确执行Map reduce Job:-
>hadoop jar <Location_of_your_JAR> <package_information_of_the_driver_class> <input_directory> <output_directory>
例如:-hadoop-jar/user/desktop/wordcount.jar com.example.wordcount_driver/user/cloudera/Dataset/input.txt/user/ccloudera/output
如果解决方案有效,请接受!