HADOOP编译WordCount.java文件报错

问题现象

使用javac编译hadoop例子wordcount.java出现报错如下。

[root@node4 hadoop]# javac -classpath ${HADOOP_HOME}/hadoop-${HADOOP_VERSION}-core.jar -d wordcount_classes WordCount.java
WordCount.java:6: error: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.*;
^
WordCount.java:7: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.*;
^
WordCount.java:8: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.*;
^
WordCount.java:9: error: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.*;
^
WordCount.java:10: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                           ^
WordCount.java:25: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
               ^
  symbol:   class Mapper
  location: class WordCount
WordCount.java:25: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                              ^
  symbol:   class Text
  location: class WordCount
WordCount.java:25: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                                    ^
  symbol:   class Text
  location: class WordCount
WordCount.java:25: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                                          ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:27: error: cannot find symbol
    private final static IntWritable one = new IntWritable(1);
                         ^
  symbol:   class IntWritable
  location: class TokenizerMapper
WordCount.java:28: error: cannot find symbol
    private Text word = new Text();
            ^
  symbol:   class Text
  location: class TokenizerMapper
WordCount.java:30: error: cannot find symbol
    public void map(Object key, Text value, Context context
                                ^
  symbol:   class Text
  location: class TokenizerMapper
WordCount.java:30: error: cannot find symbol
    public void map(Object key, Text value, Context context
                                            ^
  symbol:   class Context
  location: class TokenizerMapper
WordCount.java:41: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
               ^
  symbol:   class Reducer
  location: class WordCount
WordCount.java:41: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                       ^
  symbol:   class Text
  location: class WordCount
WordCount.java:41: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                            ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:41: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                                        ^
  symbol:   class Text
  location: class WordCount
WordCount.java:41: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                                             ^
  symbol:   class IntWritable
  location: class WordCount
WordCount.java:42: error: cannot find symbol
    private IntWritable result = new IntWritable();
            ^
  symbol:   class IntWritable
  location: class IntSumReducer
WordCount.java:44: error: cannot find symbol
    public void reduce(Text key, Iterable<IntWritable> values,
                       ^
  symbol:   class Text
  location: class IntSumReducer
WordCount.java:44: error: cannot find symbol
    public void reduce(Text key, Iterable<IntWritable> values,
                                          ^
  symbol:   class IntWritable
  location: class IntSumReducer
WordCount.java:45: error: cannot find symbol
                       Context context
                       ^
  symbol:   class Context
  location: class IntSumReducer
WordCount.java:27: error: cannot find symbol
    private final static IntWritable one = new IntWritable(1);
                                               ^
  symbol:   class IntWritable
  location: class TokenizerMapper
WordCount.java:28: error: cannot find symbol
    private Text word = new Text();
                            ^
  symbol:   class Text
  location: class TokenizerMapper
WordCount.java:42: error: cannot find symbol
    private IntWritable result = new IntWritable();
                                     ^
  symbol:   class IntWritable
  location: class IntSumReducer
WordCount.java:48: error: cannot find symbol
      for (IntWritable val : values) {
           ^
  symbol:   class IntWritable
  location: class IntSumReducer
WordCount.java:57: error: cannot find symbol
    Configuration conf = new Configuration();
    ^
  symbol:   class Configuration
  location: class WordCount
WordCount.java:57: error: cannot find symbol
    Configuration conf = new Configuration();
                             ^

原因

import与hadoop有关的类,失败。是因为/etc/profile里面关于hadoop的classpath定义不正确。

解决方法

编辑/etc/profile然后source /etc/profile
增加如下代码

export CLASSPATH=.:$HADOOP_HOME/share/hadoop/common/hadoop-common-2.7.4.jar:$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.7.4.jar:$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar:$CLASSPATH

验证

[root@node4 hadoop]# javac -d wordcount_classes WordCount.java
[root@node4 hadoop]# 

OK了。


javac 是java语言编程编译器,全称javacompilation。
javac工具读由java语言编写的类和接口的定义,并将它们编译成字节代码的class文件。

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值