【问题标题】:Hadoop: Unable to find classesHadoop:找不到类
【发布时间】:2014-11-29 13:57:27
【问题描述】:

我刚刚开始学习 hadoop 并遵循“Hadoop - The Definitive Guide”。

我测试了第一种编写 Map 和 Reduce 类的方法,其中 Mapper 和 Reducer 是接口。代码运行良好。 然后我开始编写代码,其中 Map 和 Reduce 是具有 Context 类的抽象类。 顺便说一句,我正在使用 hadoop 1.2.1 我看到以下错误

MaxTemperatureReducer.java:5: error: cannot find symbol
public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable> 
                                       ^
  symbol: class Reducer
MaxTemperatureReducer.java:7: error: cannot find symbol
    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException,InterruptedException 
                                                           ^
  symbol:   class Context
  location: class MaxTemperatureReducer
MaxTemperature.java:5: error: cannot find symbol
import org.apache.hadoop.mapreduce.FileInputFormat;
                              ^
  symbol:   class FileInputFormat
  location: package org.apache.hadoop.mapreduce
MaxTemperature.java:6: error: cannot find symbol
import org.apache.hadoop.mapreduce.FileOutputFormat;
                              ^
  symbol:   class FileOutputFormat
  location: package org.apache.hadoop.mapreduce
MaxTemperature.java:7: error: cannot find symbol
import org.apache.hadoop.mapreduce.JobClient;

我的 Mapper 类看起来像

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.MapReduceBase;
import org.apache.hadoop.mapreduce.Mapper;
public class MaxTemperatureMapper 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(0, 4);
    int airTemperature;
    if (line.charAt(4) == '+')
    {
        airTemperature = Integer.parseInt(line.substring(5, 10));
    }
    else
    {
        System.out.println( line );
        airTemperature = Integer.parseInt(line.substring(4, 9));
    }
    System.out.println( "Mapper: " + year + ", " + airTemperature );
    context.write(new Text(year), new IntWritable(airTemperature));
    }
}

有人可以帮忙吗?

【问题讨论】:

  • 你在类路径中有需要的 jar 文件吗?
  • 是的。我从命令行给出以下 jar。 "/usr/local/hadoop/hadoop-core-1.2.1.jar"
  • 请粘贴您用于编译的确切命令。
  • 我有三个文件,Mapper、Reducer 和 main。 "javac -classpath /usr/local/hadoop/hadoop-core-1.2.1.jar -d MaxTemp_classes/MaxTemperatureMapper.java MaxTemperatureReducer.java MaxTemperature.java"
  • 并且您的 jar 文件位于 /usr/local/hadoop/hadoop-core-1.2.1.jar 位置?

标签: hadoop bigdata


【解决方案1】:

似乎问题在于您的驱动程序类中的导入语句,您试图对FileInputFormatFileOutputFormat 使用错误的导入语句。在 Driver(MaxTemperature) 类中使用这些导入语句而不是 FileInputFormatFileOutputFormat

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

使用此example 作为参考,以确保您的所有导入语句都有效。

【讨论】:

    【解决方案2】:

    您的导入语句不正确。这些类文件在 org.apache.hadoop.mapred 包或 org.apache.hadoop.mapreduce.lib.input 中可用

    FileOutputFormat 也存在类似问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多