0

我一直在单个节点上测试 map reduce 作业,它似乎可以工作,但现在我试图在远程集群上运行它,我得到了 ClassNotFoundExcepton。我的代码结构如下:

public class Pivot {
    public static class Mapper extends TableMapper<ImmutableBytesWritable, ImmutableBytesWritable> {
        @Override
        public void map(ImmutableBytesWritable rowkey, Result values, Context context) throws IOException {
            (map code)
        }
    }

    public static class Reducer extends TableReducer<ImmutableBytesWritable, ImmutableBytesWritable, ImmutableBytesWritable> {
        public void reduce(ImmutableBytesWritable key, Iterable<ImmutableBytesWritable> values, Context context) throws IOException, InterruptedException {
            (reduce code)
        }
    }

    public static void main(String[] args) {
        Configuration conf = HBaseConfiguration.create();
        conf.set("fs.default.name", "hdfs://hadoop-master:9000");
        conf.set("mapred.job.tracker", "hdfs://hadoop-master:9001");
        conf.set("hbase.master", "hadoop-master:60000");
        conf.set("hbase.zookeeper.quorum", "hadoop-master");
        conf.set("hbase.zookeeper.property.clientPort", "2222");
        Job job = new Job(conf);
        job.setJobName("Pivot");
        job.setJarByClass(Pivot.class);
        Scan scan = new Scan();
        TableMapReduceUtil.initTableMapperJob("InputTable", scan, Mapper.class, ImmutableBytesWritable.class, ImmutableBytesWritable.class, job);
        TableMapReduceUtil.initTableReducerJob("OutputTable", Reducer.class, job);
        job.waitForCompletion(true);
    }
}

我尝试运行此作业时收到的错误如下:

java.lang.RuntimeException: java.lang.ClassNotFoundException: Pivot$Mapper
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:857)
    ...

有什么我想念的吗?为什么这个工作很难找到映射器?

4

1 回答 1

0

When running a job from Eclipse it's important to note that Hadoop requires you to launch your job from a jar. Hadoop requires this so it can send your code up to HDFS / JobTracker.

In your case i imagine you haven't bundled up your job classes into a jar, and then run the program 'from the jar' - resulting in a CNFE.

Try building a jar and running from the command line using hadoop jar myjar.jar ..., once this works then you can test running from within Eclipse

于 2013-11-15T02:22:08.317 回答