Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Hortonworks沙盒Hadoop平台中运行mapreduce作业_Java_Hadoop - Fatal编程技术网

Java 如何在Hortonworks沙盒Hadoop平台中运行mapreduce作业

Java 如何在Hortonworks沙盒Hadoop平台中运行mapreduce作业,java,hadoop,Java,Hadoop,我是Hadoop新手。我已经为安装了oracle虚拟盒,并在虚拟机中安装了hortonworks沙盒的映像。我还在eclipse中编写了wordcount程序,并尝试在虚拟机中运行该程序。但是我得到了一个异常树。我张贴的程序和错误树也 public class WordCount { public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWr

我是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);

}

}
公共类字数{
公共静态类映射扩展了MapReduceBase实现
制图员{
私有最终静态IntWritable one=新的IntWritable(1);
私有文本字=新文本();
公共无效映射(可长写键、文本值、,
OutputCollector输出,报告器(报告器)
抛出IOException{
字符串行=value.toString();
StringTokenizer标记器=新的StringTokenizer(行);
while(tokenizer.hasMoreTokens()){
set(tokenizer.nextToken());
输出。收集(字,一);
}
}
}
公共静态类Reduce扩展了MapReduceBase实现
减速器{
public void reduce(文本键、迭代器值、,
OutputCollector输出,报告器(报告器)
抛出IOException{
整数和=0;
while(values.hasNext()){
sum+=values.next().get();
}
collect(key,newintwriteable(sum));
}
}
公共静态void main(字符串[]args)引发IOException{
JobConf conf=newjobconf(WordCount.class);
conf.setJobName(“字数”);
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);
setInputPath(conf,新路径(args[0]);
setOutputPath(conf,新路径(args[1]);
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(urlassloader.java:202) 位于java.security.AccessController.doPrivileged(本机方法) 位于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+沙盒+1.3+虚拟盒+RC6这个版本。

您没有正确调用hadoop,缺少空格和参数。试一试

hadoop jar /usr/lib/wordcount.jar WordCount <the path to your input file on HDFS> <the path to your output directory on HDFS>
hadoop jar/usr/lib/wordcount.jar wordcount
如果找不到另一个类,请尝试使用完整的类名WordCount(例如com.mysite.WordCount)。我看不出它在哪个包中。

我认为除非您提供异常堆栈,否则任何人都无法提出解决方案trace@Ankur我已经发布了该网站的全屏截图error@AnkurShanbhag你看到了吗???我几乎看不出屏幕截图上的错误。请复制粘贴VM上显示的错误日志console@AnkurShanbhag拥有由hadoop引起的完整堆栈跟踪我不明白一件事,那就是我应该把生成的jar文件放在哪里??因为我已经在虚拟机上安装了hadoop,所以在我的机器上找不到任何物理安装。你能帮我吗?这没关系。你可以把它放在你的主目录里,或者任何你喜欢的地方。然后在“hadoop jar”后面的参数中引用它的路径你的意思是,如果我在桌面上复制这个jar,然后把它的路径放在hadoop jar c:\user\Jeet\desktop\WordCount.jar之后,是吗?我已经在桌面上粘贴了这个jar,并尝试以hadoop jar c:\user\Jeet\desktop\WordCount.jar的形式运行,但这表明不是一个有效的jar错误,你必须将它从windows机器复制到沙箱中。