如何在Hadoop2.7.0上编译mapreduce作业源代码?

8ehkhllq  于 2021-06-02  发布在  Hadoop
关注(0)|答案(6)|浏览(484)

我在ubuntu14.0.2o.s上运行hadoop2.7.0,并使用nano文本编辑器创建wordcount.java,源代码是从apachehadoop2.7.0文档复制的。
在我用这个命令编译wordcount.java之后 javac -classpath hadoop-2.7.0-core.jar -d MyJava wordcount.java ,以下是我收到的错误消息。

public class WordCount2 {
       ^
wordcount_v2.java:11: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configuration;
                             ^
wordcount_v2.java:12: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
                           ^
wordcount_v2.java:13: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.IntWritable;
                           ^
wordcount_v2.java:14: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
                           ^
wordcount_v2.java:15: error: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Job;
                                  ^
wordcount_v2.java:16: error: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Mapper;
                                  ^
wordcount_v2.java:17: error: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Reducer;
                                  ^
wordcount_v2.java:18: error: package org.apache.hadoop.mapreduce.lib.input does not exist
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
                                            ^
wordcount_v2.java:19: error: package org.apache.hadoop.mapreduce.lib.output does not exist
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
                                             ^
wordcount_v2.java:20: error: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Counter;
                                  ^
wordcount_v2.java:21: error: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.GenericOptionsParser;
                             ^
wordcount_v2.java:22: error: package org.apache.hadoop.util does not exist
import org.apache.hadoop.util.StringUtils;
                             ^
wordcount_v2.java:27: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
               ^
  symbol:   class Mapper
  location: class WordCount2
wordcount_v2.java:27: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                              ^
  symbol:   class Text
  location: class WordCount2
wordcount_v2.java:27: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                                    ^
  symbol:   class Text
  location: class WordCount2
wordcount_v2.java:27: error: cannot find symbol
       extends Mapper<Object, Text, Text, IntWritable>{
                                          ^
  symbol:   class IntWritable
  location: class WordCount2
wordcount_v2.java:31: error: cannot find symbol
    private final static IntWritable one = new IntWritable(1);
                         ^
  symbol:   class IntWritable
  location: class TokenizerMapper
wordcount_v2.java:32: error: cannot find symbol
    private Text word = new Text();
            ^
  symbol:   class Text
  location: class TokenizerMapper
wordcount_v2.java:37: error: cannot find symbol
    private Configuration conf;
            ^
  symbol:   class Configuration
  location: class TokenizerMapper
wordcount_v2.java:41: error: cannot find symbol
    public void setup(Context context) throws IOException,
                      ^
  symbol:   class Context
  location: class TokenizerMapper
wordcount_v2.java:69: error: cannot find symbol
    public void map(Object key, Text value, Context context
                                ^
  symbol:   class Text
  location: class TokenizerMapper
wordcount_v2.java:69: error: cannot find symbol
    public void map(Object key, Text value, Context context
                                            ^
  symbol:   class Context
  location: class TokenizerMapper
wordcount_v2.java:88: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
               ^
  symbol:   class Reducer
  location: class WordCount2
wordcount_v2.java:88: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                       ^
  symbol:   class Text
  location: class WordCount2
wordcount_v2.java:88: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                            ^
  symbol:   class IntWritable
  location: class WordCount2
wordcount_v2.java:88: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                                        ^
  symbol:   class Text
  location: class WordCount2
wordcount_v2.java:88: error: cannot find symbol
       extends Reducer<Text,IntWritable,Text,IntWritable> {
                                             ^
  symbol:   class IntWritable
  location: class WordCount2
wordcount_v2.java:89: error: cannot find symbol
    private IntWritable result = new IntWritable();
            ^
  symbol:   class IntWritable
  location: class IntSumReducer
wordcount_v2.java:91: error: cannot find symbol
    public void reduce(Text key, Iterable<IntWritable> values,
                       ^
  symbol:   class Text
  location: class IntSumReducer
wordcount_v2.java:91: error: cannot find symbol
    public void reduce(Text key, Iterable<IntWritable> values,
                                          ^
  symbol:   class IntWritable
  location: class IntSumReducer
wordcount_v2.java:92: error: cannot find symbol
                       Context context
                       ^
  symbol:   class Context
  location: class IntSumReducer
wordcount_v2.java:31: error: cannot find symbol
    private final static IntWritable one = new IntWritable(1);
                                               ^
  symbol:   class IntWritable
  location: class TokenizerMapper
wordcount_v2.java:32: error: cannot find symbol
    private Text word = new Text();
                            ^
  symbol:   class Text
  location: class TokenizerMapper
wordcount_v2.java:40: error: method does not override or implement a method from a supertype
    @Override
    ^
wordcount_v2.java:46: error: cannot find symbol
        URI[] patternsURIs = Job.getInstance(conf).getCacheFiles();
                             ^
  symbol:   variable Job
  location: class TokenizerMapper
wordcount_v2.java:48: error: cannot find symbol
          Path patternsPath = new Path(patternsURI.getPath());
          ^
  symbol:   class Path
  location: class TokenizerMapper
wordcount_v2.java:48: error: cannot find symbol
          Path patternsPath = new Path(patternsURI.getPath());
                                  ^
  symbol:   class Path
  location: class TokenizerMapper
wordcount_v2.java:64: error: cannot find symbol
            + StringUtils.stringifyException(ioe));
              ^
  symbol:   variable StringUtils
  location: class TokenizerMapper
wordcount_v2.java:68: error: method does not override or implement a method from a supertype
    @Override
    ^
wordcount_v2.java:80: error: cannot find symbol
        Counter counter = context.getCounter(CountersEnum.class.getName(),
        ^
  symbol:   class Counter
  location: class TokenizerMapper
wordcount_v2.java:89: error: cannot find symbol
    private IntWritable result = new IntWritable();
                                     ^
  symbol:   class IntWritable
  location: class IntSumReducer
wordcount_v2.java:95: error: cannot find symbol
      for (IntWritable val : values) {
           ^
  symbol:   class IntWritable
  location: class IntSumReducer
wordcount_v2.java:104: error: cannot find symbol
    Configuration conf = new Configuration();
    ^
  symbol:   class Configuration
  location: class WordCount2
wordcount_v2.java:104: error: cannot find symbol
    Configuration conf = new Configuration();
                             ^
  symbol:   class Configuration
  location: class WordCount2
wordcount_v2.java:105: error: cannot find symbol
    GenericOptionsParser optionParser = new GenericOptionsParser(conf, args);
    ^
  symbol:   class GenericOptionsParser
  location: class WordCount2
wordcount_v2.java:105: error: cannot find symbol
    GenericOptionsParser optionParser = new GenericOptionsParser(conf, args);
                                            ^
  symbol:   class GenericOptionsParser
  location: class WordCount2
wordcount_v2.java:111: error: cannot find symbol
    Job job = Job.getInstance(conf, "word count");
    ^
  symbol:   class Job
  location: class WordCount2
wordcount_v2.java:111: error: cannot find symbol
    Job job = Job.getInstance(conf, "word count");
              ^
  symbol:   variable Job
  location: class WordCount2
wordcount_v2.java:116: error: cannot find symbol
    job.setOutputKeyClass(Text.class);
                          ^
  symbol:   class Text
  location: class WordCount2
wordcount_v2.java:117: error: cannot find symbol
    job.setOutputValueClass(IntWritable.class);
                            ^
  symbol:   class IntWritable
  location: class WordCount2
wordcount_v2.java:122: error: cannot find symbol
        job.addCacheFile(new Path(remainingArgs[++i]).toUri());
                             ^
  symbol:   class Path
  location: class WordCount2
wordcount_v2.java:128: error: cannot find symbol
    FileInputFormat.addInputPath(job, new Path(otherArgs.get(0)));
                                          ^
  symbol:   class Path
  location: class WordCount2
wordcount_v2.java:128: error: cannot find symbol
    FileInputFormat.addInputPath(job, new Path(otherArgs.get(0)));
    ^
  symbol:   variable FileInputFormat
  location: class WordCount2
wordcount_v2.java:129: error: cannot find symbol
    FileOutputFormat.setOutputPath(job, new Path(otherArgs.get(1)));
                                            ^
  symbol:   class Path
  location: class WordCount2
wordcount_v2.java:129: error: cannot find symbol
    FileOutputFormat.setOutputPath(job, new Path(otherArgs.get(1)));
    ^
  symbol:   variable FileOutputFormat
  location: class WordCount2
56 errors

我想知道怎么会这样。我的jdk版本是1.8.0\u45

nkoocmlb

nkoocmlb1#

使用maven进行依赖关系管理。你想在这里做的事情是在地狱世界的水平。
请参阅以下链接,为hadoop项目设置maven:maven for hadoop

brjng4g3

brjng4g32#

这不是执行hadoop map reduce程序的正确方法首先您必须安装hadoop并在这个链接上配置安装指南http://www.bogotobogo.com/hadoop/bigdata_hadoop_install_on_ubuntu_single_node_cluster.php
之后这是字数计算的例子
第1部分http://www.bogotobogo.com/hadoop/bigdata_hadoop_creating_java_wordcount_project_with_eclipse_mapreduce2.php
第二部分http://www.bogotobogo.com/hadoop/bigdata_hadoop_creating_java_wordcount_project_with_eclipse_mapreduce2_part2.php
按照所有的指令一步一步地…然后你的程序将执行。。

58wvjzkj

58wvjzkj3#

这些错误是由于依赖关系造成的,您应该再添加几个库来编译而不会出现问题。图书馆可以在 HADOOP_HOME 子目录,如 ~/share/hadoop/

6psbrbz9

6psbrbz94#

只是为了补充信息,因为有些参考资料是关于hadoop的旧版本。
maven极大地简化了对引用的管理。您需要:

org.apache.hadoop:hadoop-common:2.7.0
org.apache.hadoop:hadoop-client:2.7.0
org.apache.hadoop:hadoop-auth:2.7.0
org.apache.hadoop:hadoop-hdfs:2.7.0

至少。祝你好运!

pzfprimi

pzfprimi5#

不需要下载任何较旧版本的jar文件。你应该像这样运行命令

javac -classpath `yarn classpath` -d \path-to-where-class-file-to-be-stored\ wordcount.java

p、 s.注意类路径前后的平铺字符(tab上的一个键,左至1)。

bnl4lu3b

bnl4lu3b6#

您还没有在代码中导入那些将要发生错误的类。
我想你得补充一点 hadoop-core-1.0.4.jar 将所有这些类导入到您的代码中并再次编译,它应该可以工作。
你可以接受任何版本 hadoop-core-x.y.z.jar 它不是特定于 hadoop-core-1.0.4.jar 只是。

相关问题