【问题标题】:java.lang.RuntimeException: java.lang.ClassNotFoundException when trying to run Jar job on Elastic MapReducejava.lang.RuntimeException:尝试在 Elastic MapReduce 上运行 Jar 作业时出现 java.lang.ClassNotFoundException
【发布时间】:2011-09-10 18:15:52
【问题描述】:

我应该改变什么来修复以下错误:

我正在尝试在 Elastic Mapreduce 上开始工作,但每次都会崩溃并显示以下消息:

java.lang.RuntimeException: java.lang.ClassNotFoundException: iataho.mapreduce.NewMaxTemperatureMapper
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:831)
at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:157)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:577)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:310)
at org.apache.hadoop.mapred.Child.main(Child.java:170)
Caused by: java.lang.ClassNotFoundException: iataho.mapreduce.NewMaxTemperatureMapper
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:778)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:829)
... 4 more

NewMaxTemperatureMapper 已声明并且我已经检查过,它包含在 jar 中,而不是位于 s3。 以下是所有应用类的代码:

NewMaxTemperature.java:

package iataho.mapreduce;

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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class NewMaxTemperature {
/**
 * @param args
 */
public static void main(String[] args) {

    try {
        if (args.length != 2) {
            System.err.println("Usage: NewMaxTemperature <input path> <output path>");
            System.exit(123);
        }
        Job job = new Job();
        job.setJarByClass(NewMaxTemperature.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(NewMaxTemperatureMapper.class);
        job.setCombinerClass(NewMaxTemperatureReducer.class);
        job.setReducerClass(NewMaxTemperatureReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

}

NewMaxTemperatureReducer.java:

package iataho.mapreduce;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class NewMaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
    int maxValue = Integer.MIN_VALUE;
    for (IntWritable value : values) {
        maxValue = Math.max(maxValue, value.get());
    }
    context.write(key, new IntWritable(maxValue));
}
}

NewMaxTemperatureMapper.java:

package iataho.mapreduce;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class NewMaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private static final int    MISSING = 9999;

public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String line = value.toString();
    String year = line.substring(15, 19);
    int airTemperature;
    if (line.charAt(87) == '+') { // parseInt doesn't like leading plus
                                    // signs
        airTemperature = Integer.parseInt(line.substring(88, 92));
    } else {
        airTemperature = Integer.parseInt(line.substring(87, 92));
    }
    String quality = line.substring(92, 93);
    if (airTemperature != MISSING && quality.matches("[01459]")) {
        context.write(new Text(year), new IntWritable(airTemperature));
    }
}
}

我已经在此处创建了用于导致此崩溃的 jar 文件:download jar

【问题讨论】:

    标签: java hadoop mapreduce amazon-emr elastic-map-reduce


    【解决方案1】:

    在执行应用程序时检查您包含的 jar。请向有关此问题的问题添加更多信息。

    ===

    好的。问题是我使用了 eclipse 选项“将库打包到生成的 JAR 中”。我将其更改为“将生成的库提取到生成的 JAR 中”,现在它可以正常工作了

    【讨论】:

    • 所有jar都已经用eclipse编译成一个单独的执行jar;无论如何,它找不到我的类之一,它是公共的并且与主类在同一个包中
    • 我已经把罐子放到网上,以便有人想看看它
    • 该链接下载 test.zip 与几个 jar 和您的类,而不是您构建的 jar。如果缺少任何类,请检查构建 jar 配置,因为某些类可能不包含在 jar 中。
    • 这是我放在 s3 上供 EMR 使用的罐子。我应该放其他东西吗?
    • 不确定 EMR 应该遵循哪种 jar 结构。
    猜你喜欢
    • 2014-05-10
    • 2015-06-23
    • 2013-01-16
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    相关资源
    最近更新 更多