【问题标题】:How to run a mapreduce job in Hortonworks sandbox Hadoop platform如何在 Hortonworks 沙盒 Hadoop 平台中运行 mapreduce 作业
【发布时间】:2014-01-01 12:59:58
【问题描述】:

我是 Hadoop 的新手。我已经为虚拟机安装了 oracle 虚拟机并安装了 hortonworks 沙箱的图像。我还在 eclipse 中编写了 wordcount 程序并尝试在虚拟机中运行它。但是我得到了一个异常树。我也在发布程序和错误树。

public class WordCount {

public static class Map extends MapReduceBase implements
        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,
            OutputCollector<Text, IntWritable> output, Reporter reporter)
            throws IOException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            output.collect(word, one);
        }
    }
}

public static class Reduce extends MapReduceBase implements
        Reducer<Text, IntWritable, Text, IntWritable> {
    public void reduce(Text key, Iterator<IntWritable> values,
            OutputCollector<Text, IntWritable> output, Reporter reporter)
            throws IOException {
        int sum = 0;
        while (values.hasNext()) {
            sum += values.next().get();
        }
        output.collect(key, new IntWritable(sum));
    }
}

public static void main(String[] args) throws IOException {
    JobConf conf = new JobConf(WordCount.class);
    conf.setJobName("wordcount");

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(Map.class);
    conf.setCombinerClass(Reduce.class);
    conf.setReducerClass(Reduce.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    JobClient.runJob(conf);

}

}

[hue@sandbox`]$hadoop jar/usr/lib/wordcount.jar wordcount[-m][-r]

线程主 java.lang.NoClassDefFoundError:jar/usr/lib/wordcount/jar 中的异常

引起:java.lang.ClassNotFoundException:jar.usr.lib.wordcount.jar 在 java.net.URLClassLoader$1.run(URLlassLoader.java:202) 在 java.security.AccessController.doPriviledged(本机方法) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:190) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:306) 在 sun.misc.Launcher$AppClassLoader.loadClass(Laucher.java:301) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:247)

找不到主类:jar/usr/lib/wordcount.jar

我在 64 位机器上使用 Hortonworks+Sandbox+1.3+VirtualBox+RC6 这个版本。

【问题讨论】:

  • 除非您提供异常堆栈跟踪,否则我认为没有人可以提出解决方案
  • @Ankur 我已经发布了错误的全屏截图
  • @AnkurShanbhag 你看到了吗????
  • 我几乎无法从屏幕截图中找出错误。请复制粘贴您的 VM 控制台上显示的错误日志
  • @AnkurShanbhag 发布了由 hadoop 引起的完整堆栈跟踪

标签: java hadoop


【解决方案1】:

您没有正确调用 hadoop,您缺少一个空格以及 args。试试

hadoop jar /usr/lib/wordcount.jar WordCount <the path to your input file on HDFS> <the path to your output directory on HDFS>

如果找不到其他类,请尝试使用 WordCount 的完整类名(例如,com.mysite.WordCount)。我看不到它在哪个包中。

【讨论】:

  • 我无法理解将生成的 jar 文件放在哪里的一件事?因为我已经在虚拟机上安装了 hadoop,我在我的机器上找不到任何物理安装。你能帮我吗那个??
  • 没关系。你可以把它放在你的主目录中,或者任何你喜欢的地方。然后在“hadoop jar”后面的参数中引用它的路径
  • 你的意思是如果我把那个 jar 复制到桌面然后把它的路径放在 hadoop jar c:\user\Jeet\Desktop\WordCount.jar 之后是吗??
  • 我已将 jar 粘贴到桌面并尝试以 hadoop jar c:\user\Jeet\Desktop\WordCount.jar 运行,但显示不是有效的 jar 错误
  • 你必须将它从你的 windows 机器复制到沙箱中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-10
  • 1970-01-01
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 2014-08-20
相关资源
最近更新 更多