java.lang.ClassNotFoundException: Class mapreduce.WordcountMapper not found hadoop

  • Post author:
  • Post category:java


环境: hadoop2.7

问题:idea远程连接hadoop,运行mapreduce的程序的时候出错

分析:

可以看到 日志里面打了一行jar没有提交什么的

2020-09-12 14:40:38,391 INFO [org.apache.hadoop.mapreduce.JobSubmitter] - Submitting tokens for job: job_1599887687347_0009
2020-09-12 14:40:38,481 INFO [org.apache.hadoop.mapred.YARNRunner] - Job jar is not present. Not adding any jar to the list of resources.
2020-09-12 14:40:38,519 INFO [org.apache.hadoop.yarn.client.api.impl.YarnClientImpl] - Submitted application application_1599887687347_0009

然后查看org.apache.hadoop.mapred.YARNRunner 这个类搜索job jar is not present

源码里面这样写着

if (jobConf.get(MRJobConfig.JAR) != null) {
      Path jobJarPath = new Path(jobConf.get(MRJobConfig.JAR));
      LocalResource rc = createApplicationResource(
          FileContext.getFileContext(jobJarPath.toUri(), jobConf),
          jobJarPath,
          LocalResourceType.PATTERN);
      String pattern = conf.getPattern(JobContext.JAR_UNPACK_PATTERN, 
          JobConf.UNPACK_JAR_PATTERN_DEFAULT).pattern();
      rc.setPattern(pattern);
      localResources.put(MRJobConfig.JOB_JAR, rc);
    } else {
      // Job jar may be null. For e.g, for pipes, the job jar is the hadoop
      // mapreduce jar itself which is already on the classpath.
      LOG.info("Job jar is not present. "
          + "Not adding any jar to the list of resources.");
    }

是对jobConf里面是否包含那个参数进行判断,所以就报了这个错误

MRJobConfig.JAR="mapreduce.job.jar";

对这个类dubug的时候发现确实没有这个参数,可以看到结果为false

解决方法:

打一个jar包,在conf里面设置这个参数的对应路径  或者像源码里面说的在classpath里面设置一下(没试过)

configuration.set("mapreduce.job.jar",
               "E:\\workspace\\mapreduce.jar");



版权声明:本文为stupidTomA原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。