从未找到的eclipse错误类提交Hadoop作业

时间:2014-09-23 05:55:28

标签: java eclipse hadoop mapreduce cloudera

我正在尝试从eclipse向jobtracker提交mapreduce作业(在这种情况下,它在本地计算机上运行)

这是代码

package org.myorg;

import org.apache.hadoop.conf.Configuration;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

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

        conf.set("fs.defaultFS", "hdfs://localhost:8020");
        conf.set("mapred.job.tracker", "localhost:8021");

        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("hdfs://localhost:8020/tmp/nages/cooper.txt"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:8020/tmp/nages/output"));

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

}

映射文件

package org.myorg;

import java.io.IOException;
import java.util.StringTokenizer;

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 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);
        }
    }
}

Reducer文件

package org.myorg;

import java.io.IOException;

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

public 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));
    }
}

我收到以下错误

14/09/23 11:09:41 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/09/23 11:09:42 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/09/23 11:09:42 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/09/23 11:09:42 INFO input.FileInputFormat: Total input paths to process : 1
14/09/23 11:09:42 WARN conf.Configuration: fs.default.name is deprecated. Instead, use fs.defaultFS
14/09/23 11:09:43 INFO mapred.JobClient: Running job: job_201409221650_0012
14/09/23 11:09:44 INFO mapred.JobClient:  map 0% reduce 0%
14/09/23 11:09:50 INFO mapred.JobClient: Task Id : attempt_201409221650_0012_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.myorg.Map not found
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1774)
    at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:191)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:631)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
    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:1408)
    at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.lang.ClassNotFoundException: Class org.myorg.Map not found
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1680)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1772)
    ... 8 more

如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

localhost:检查本地Filesystem

中的文件

尝试提供HDFS ip而不是localhost

config.set("fs.defaultFS", "hdfs://HDFSclusterip:8020/");
config.set("hadoop.job.ugi", "hdfs");

对于输入/输出

  

FileInputFormat.addInputPath(job,new   路径( “HDFS:// HDFSclusterip:8020 / TMP /纳热/ cooper.txt”));   FileOutputFormat.setOutputPath(job,new   路径( “HDFS:// HDFSclusterip:8020 / TMP /纳热/输出”));

如果有效,请告诉我。

答案 1 :(得分:-1)

它的jar问题,找不到Map类。 添加到驱动程序代码,job.setJarByClass(WordCount.class);

干杯!