在编译WordCount.java时,我一直收到一条错误,上面写着“找不到符号”。我尝试导入其他库,但它只会增加错误列表。我错过了一些需要添加的组件吗?
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
答案 0 :(得分:0)
你可以尝试这个:
javac -classpath hadoop-core-1.2.1.jar:lib/commons-cli-1.2.jar -d [path where u want to put the result] [path]/WordCount.java
答案 1 :(得分:0)
您的类路径似乎不包含所有必需的库和jar。
对于hadoop 2.7,您可以轻松运行:
$hadoop classpath
这将返回您需要包含在类路径中的libs和jar的完整列表。
或更简单,您可以在编译代码时使用上述命令
$ javac -classpath $(hadoop classpath) -d wordcount_classes WordCount.java
答案 2 :(得分:0)
这是因为必要的包不包含在javac类路径中。
对于hadoop 2.7.3,添加3个包对我有用:
javac -classpath $HADOOP_HOME$/share/hadoop/common/hadoop-common-2.7.3.jar:$HADOOP_HOME$/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.7.3.jar:$HADOOP_HOME$/share/hadoop/common/lib/commons-cli-1.2.jar
-d wordcount_classes WordCount.java
答案 3 :(得分:0)
其他一些答案切入追逐,并提供实用,快速的解决方案 - 这将有效 - 但official Hadoop Wordcount tutorial建议您从javac
致电bin/hadoop
。这样,Hadoop将负责其自己的库的类路径冲突。
然而above-mentioned tutorial可能会误导您将HADOOP_CLASSPATH
指向错误的lib
目录(JDK和JRE有明显的目录),因此缺少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_HOME
和HADOOP_PREFIX
的实际值必须指向计算机上实际安装这些工具的位置。
*它会在编译时导致Error: Could not find or load main class com.sun.tools.javac.Main