如何在Hortonworks沙盒中编译WordCount.java?

时间:2019-03-24 13:01:51

标签: hadoop hortonworks-sandbox

我正在遵循一个教程,并尝试在Hortonworks Data Platform Sandbox中运行WordCount示例。但是,当我尝试从命令行进行编译时,出现错误并且无法构建它。

在终端我输入Java编译命令:

$ javac WordCount.java

出现以下错误,而不是编译并获取.class文件:

WordCount.java:27: error: package org.apache.hadoop.conf does not exist

import org.apache.hadoop.conf.Configuration;

^

WordCount.java:28: error: package org.apache.hadoop.conf does not exist

import org.apache.hadoop.conf.Configured;

^

WordCount.java:29: error: package org.apache.hadoop.fs does not exist

import org.apache.hadoop.fs.Path;

^

WordCount.java:30: error: package org.apache.hadoop.io does not exist

import org.apache.hadoop.io.IntWritable;

^

WordCount.java:31: error: package org.apache.hadoop.io does not exist

import org.apache.hadoop.io.LongWritable;

^

WordCount.java:32: error: package org.apache.hadoop.io does not exist

import org.apache.hadoop.io.Text;

^

WordCount.java:42: error: package org.apache.hadoop.util does not exist

import org.apache.hadoop.util.Tool;

^

WordCount.java:43: error: package org.apache.hadoop.util does not exist

import org.apache.hadoop.util.ToolRunner;

^

WordCount.java:54: error: cannot find symbol

public class WordCount extends Configured implements Tool {

^

symbol: class Configured

WordCount.java:54: error: cannot find symbol

public class WordCount extends Configured implements Tool {

^

symbol: class Tool

WordCount.java:61: error: cannot access Closeable

public static class MapClass extends MapReduceBase

^

class file for org.apache.hadoop.io.Closeable not found

WordCount.java:64: error: cannot find symbol

private final static IntWritable one = new IntWritable(1);

^

symbol: class IntWritable

location: class MapClass

WordCount.java:65: error: cannot find symbol

private Text word = new Text();

^

symbol: class Text

location: class MapClass

WordCount.java:67: error: cannot find symbol

public void map(LongWritable key, Text value,

^

symbol: class LongWritable

location: class MapClass

WordCount.java:67: error: cannot find symbol

public void map(LongWritable key, Text value,

^

symbol: class Text

location: class MapClass

WordCount.java:68: error: cannot find symbol

OutputCollector<Text, IntWritable> output,

^

symbol: class Text

location: class MapClass

WordCount.java:68: error: cannot find symbol

OutputCollector<Text, IntWritable> output,

^

symbol: class IntWritable

location: class MapClass

WordCount.java:83: error: cannot find symbol

implements Reducer<Text, IntWritable, Text, IntWritable> {

^

symbol: class Text

location: class WordCount

WordCount.java:83: error: cannot find symbol

implements Reducer<Text, IntWritable, Text, IntWritable> {

^

symbol: class IntWritable

location: class WordCount

WordCount.java:83: error: cannot find symbol

implements Reducer<Text, IntWritable, Text, IntWritable> {

^

symbol: class Text

location: class WordCount

WordCount.java:83: error: cannot find symbol

implements Reducer<Text, IntWritable, Text, IntWritable> {

^

symbol: class IntWritable

location: class WordCount

WordCount.java:85: error: cannot find symbol

public void reduce(Text key, Iterator<IntWritable> values,

^

symbol: class Text

location: class Reduce

WordCount.java:85: error: cannot find symbol

public void reduce(Text key, Iterator<IntWritable> values,

^

symbol: class IntWritable

location: class Reduce

WordCount.java:86: error: cannot find symbol

OutputCollector<Text, IntWritable> output,

^

symbol: class Text

location: class Reduce

WordCount.java:86: error: cannot find symbol

OutputCollector<Text, IntWritable> output,

^

symbol: class IntWritable

location: class Reduce

我在做什么错?我使用的是当前版本的Hortonworks Sandbox 2.6.1。 Hadoop版本为3.1.1

1 个答案:

答案 0 :(得分:0)

您需要指定正确的类路径。在沙箱中,您可以使用hadoop类路径信息。

尝试一下(注意引号,它们必须是反引号!“`”):

$ javac -cp `hadoop classpath` WordCount.java