编译WordCount.java时出现编译错误 [英] Compilation errors while compiling WordCount.java

查看:178
本文介绍了编译WordCount.java时出现编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译WordCount.java时,我不断收到提示找不到符号"的错误.我尝试导入其他库,但它只会加到错误列表中.我是否缺少一些需要添加的组件?

I keep getting an error which says 'cannot find symbol' while compiling WordCount.java. I tried importing the other libraries, but it only adds up to the list of errors. Am I missing some component that needs to be added?

  javac -classpath /Documents/hadoop/hadoop-1.2.1/hadoop-core-1.2.1.jar:/Documents/hadoop/hadoop-1.2.1/lib/commons-cli-1.2.jar -d wordcount_classes WordCount.java


    WordCount.java:4: error: package org.apache.hadoop.fs does not exist
    import org.apache.hadoop.fs.Path;
                               ^
    WordCount.java:5: error: package org.apache.hadoop.io does not exist
    import org.apache.hadoop.io.*;
    ^
    WordCount.java:6: error: package org.apache.hadoop.mapred does not exist
    import org.apache.hadoop.mapred.*;
    ^
    WordCount.java:8: error: package org.apache.hadoop.mapred.lib.input does not exist
    import org.apache.hadoop.mapred.lib.input.FileInputFormat;
                                             ^
    WordCount.java:9: error: package org.apache.hadoop.mapred.lib.output does not exist
    import org.apache.hadoop.mapred.lib.output.FileOutputFormat;
                                          ^
    WordCount.java:10: error: package org.apache.hadoop.mapred.lib.input does not exist
    import org.apache.hadoop.mapred.lib.input.TextInputFormat;
                                         ^
    WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable,    Text, Text, IntWritable> {
                                        ^
    symbol:   class MapReduceBase
    location: class WordCount
    WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable,   Text, Text, IntWritable> {
                                                                 ^
    symbol:   class Mapper
    location: class WordCount
    WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable,     Text, Text, IntWritable> {
                                                                        ^
    symbol:   class LongWritable
    location: class WordCount
    WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                                                                      ^
    symbol:   class Text
    location: class WordCount 
    WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable,     Text, Text, IntWritable> {
                                                                                             ^
    symbol:   class Text
    location: class WordCount
WordCount.java:15: error: cannot find symbol
        public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
                                                                                                  ^
    symbol:   class IntWritable
    location: class WordCount
    WordCount.java:16: error: cannot find symbol
          private final static IntWritable one = new IntWritable(1);
                               ^
    symbol:   class IntWritable
    location: class Map
    WordCount.java:17: error: cannot find symbol
          private Text word = new Text();
                  ^
    symbol:   class Text
    location: class Map
    WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                          ^
    symbol:   class LongWritable
    location: class Map
    WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable>   output, Reporter reporter) throws IOException {
                                            ^
    symbol:   class Text
    location: class Map
    WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable>     output, Reporter reporter) throws IOException {
                                                        ^
    symbol:   class OutputCollector
    location: class Map
    WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                        ^
  symbol:   class Text
  location: class Map
WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                              ^
  symbol:   class IntWritable
  location: class Map
WordCount.java:19: error: cannot find symbol
          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                                                   ^
  symbol:   class Reporter
  location: class Map
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                           ^
  symbol:   class MapReduceBase
  location: class WordCount
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                    ^
  symbol:   class Reducer
  location: class WordCount
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                            ^
  symbol:   class Text
  location: class WordCount
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                                  ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                                               ^
  symbol:   class Text
  location: class WordCount
WordCount.java:28: error: cannot find symbol
        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
                                                                                                     ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                             ^
  symbol:   class Text
  location: class Reduce
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                ^
  symbol:   class IntWritable
  location: class Reduce
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                     ^
  symbol:   class OutputCollector
  location: class Reduce
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                                     ^
  symbol:   class Text
  location: class Reduce
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                                           ^
  symbol:   class IntWritable
  location: class Reduce
WordCount.java:29: error: cannot find symbol
          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
                                                                                                                ^
  symbol:   class Reporter
  location: class Reduce
WordCount.java:16: error: cannot find symbol
          private final static IntWritable one = new IntWritable(1);
                                                     ^
  symbol:   class IntWritable
  location: class Map
WordCount.java:17: error: cannot find symbol
          private Text word = new Text();
                                  ^
  symbol:   class Text
  location: class Map
WordCount.java:34: error: cannot find symbol
            output.collect(key, new IntWritable(sum));
                                    ^
  symbol:   class IntWritable
  location: class Reduce
WordCount.java:39: error: cannot find symbol
          JobConf conf = new JobConf(WordCount.class);
          ^
  symbol:   class JobConf
  location: class WordCount
WordCount.java:39: error: cannot find symbol
          JobConf conf = new JobConf(WordCount.class);
                             ^
  symbol:   class JobConf
  location: class WordCount
WordCount.java:42: error: cannot find symbol
          conf.setOutputKeyClass(Text.class);
                                 ^
  symbol:   class Text
  location: class WordCount
WordCount.java:43: error: cannot find symbol
          conf.setOutputValueClass(IntWritable.class);
                                   ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:49: error: cannot find symbol
          conf.setInputFormat(TextInputFormat.class);
                              ^
  symbol:   class TextInputFormat
  location: class WordCount
WordCount.java:50: error: cannot find symbol
          conf.setOutputFormat(TextOutputFormat.class);
                               ^
  symbol:   class TextOutputFormat
  location: class WordCount
WordCount.java:52: error: cannot find symbol
          FileInputFormat.setInputPaths(conf, new Path(args[0]));
                                                  ^
  symbol:   class Path
  location: class WordCount
WordCount.java:52: error: cannot find symbol
          FileInputFormat.setInputPaths(conf, new Path(args[0]));
          ^
  symbol:   variable FileInputFormat
  location: class WordCount
WordCount.java:53: error: cannot find symbol
          FileOutputFormat.setOutputPath(conf, new Path(args[1]));
                                                   ^
  symbol:   class Path
  location: class WordCount
WordCount.java:53: error: cannot find symbol
          FileOutputFormat.setOutputPath(conf, new Path(args[1]));
          ^
  symbol:   variable FileOutputFormat
  location: class WordCount
WordCount.java:55: error: cannot find symbol
      JobClient.runJob(conf);
      ^
  symbol:   variable JobClient
  location: class WordCount
46 errors

推荐答案

其他一些答案切合实际,并给出了务实,快速的解决方案-可以奏效-但

Some of the other answers cut to the chase and give pragmatic, quick solutions - which will work - but the official Hadoop Wordcount tutorial recommends that you call javac from bin/hadoop. This way, Hadoop will take care of the classpath conflicts for its own libraries.

但是,上述教程可能会误导您将HADOOP_CLASSPATH指向错误的lib目录(JDK和JRE有不同的目录),从而丢失了tools.jar. *

The above-mentioned tutorial could however mislead you to point HADOOP_CLASSPATH to the wrong lib directory (there are distinct ones for the JDK and the JRE) thus missing tools.jar.*

我的解决方法如下:

$ export HADOOP_PREFIX="${absolute/path/to/your/hadoop/binaries}"
$ export JDK_HOME="${absolute/path/to/your/jdk}"  

$ export JAVA_HOME="${JDK_HOME}/jre"  
$ export PATH="${JAVA_HOME}/bin:${PATH}"  
$ export HADOOP_CLASSPATH="${JDK_HOME}/lib/tools.jar"  

$ cd $HADOOP_PREFIX
$ bin/hadoop com.sun.tools.javac.Main ./path/to/WordCount.java  

注意,要分配给JAVA_HOMEHADOOP_PREFIX的实际值必须指向在计算机上实际安装这些工具的位置.

Note that the actual values to assign to JAVA_HOME and HADOOP_PREFIX must point to the locations where those tools are actually installed on your machine.

*它会在编译时导致Error: Could not find or load main class com.sun.tools.javac.Main

* it would cause Error: Could not find or load main class com.sun.tools.javac.Main at compile-time

这篇关于编译WordCount.java时出现编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆