java - 未设置作业 jar 文件。 Hadoop 中可能找不到用户类

标签 java debugging hadoop

我正在尝试运行 MR wordcount 作业。但我没有设置作业 jar 文件集。我正在发布堆栈跟踪,有人可以帮助我吗?

14/01/27 16:52:26 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/01/27 16:52:26 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/01/27 16:52:26 INFO input.FileInputFormat: Total input paths to process : 1
14/01/27 16:52:26 INFO util.NativeCodeLoader: Loaded the native-hadoop library
14/01/27 16:52:26 WARN snappy.LoadSnappy: Snappy native library not loaded
14/01/27 16:52:27 INFO mapred.JobClient: Running job: job_201401271610_0002
14/01/27 16:52:28 INFO mapred.JobClient:  map 0% reduce 0%
14/01/27 16:52:35 INFO mapred.JobClient: Task Id : attempt_201401271610_0002_m_000000_0,   Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.gamma.WordCount$Map
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:849)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1149)

我正在运行这个命令

hadoop jar wordcount.jar org.gamma.WordCount /user/jeet/getty/gettysburg.txt /user/jeet/getty1/out

这是我的字数统计课

import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

 public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            context.write(word, one);
        }
    }
 } 

 public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
      throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.get();
        }
        context.write(key, new IntWritable(sum));
    }
 }

 public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();

    Job job = new Job(conf, "WordCount");

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.setMapperClass(Map.class);
    job.setReducerClass(Reduce.class);

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    job.waitForCompletion(true);
    job.setJarByClass(WordCount.class);
 }

}

最佳答案

在告诉作业哪个 JAR 类对应于它之前,您正在提交作业。您的错误消息中非常清楚:

14/01/27 16:52:26 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).

交换驱动程序的最后两行,它会工作:

 job.setJarByClass(WordCount.class);
 job.waitForCompletion(true);

关于java - 未设置作业 jar 文件。 Hadoop 中可能找不到用户类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21379589/

相关文章:

java - 将字符串表达式计算为整数?

hadoop - 用于 Hadoop 作业的 Cassandra 与 HBase

logging - 如何使用 Pig 从列中解析 JSON 字符串

Java 有多种形式

java - LongAccumulator 没有得到正确的结果

java - 使用标准 main(String [] args) 方法运行单个 java 文件 - Android Studio

flash - 如何追踪网页内的ActionScript?

ios - 为什么我无法在调试器中打印该变量的值?

android - 是否可以检测到 Android 设备上的 USB 调试?

hadoop - 对我来说,让 Hadoop 在私有(private) OpenStack 云上运行的最有效方法是什么