【问题标题】:Which files has to be added in plugins to open the hadoop mapreduce source code in eclipseeclipse中打开hadoop mapreduce源码需要在插件中添加哪些文件
【发布时间】:2017-03-10 15:54:19
【问题描述】:

假设我在 Eclipse 中编写了以下代码

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

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

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

现在,假设我想打开 Job/Configuration 对象的源代码(很明显,通过按下 ctrl 来单击它),eclipse 会抛出错误,提示使用附加源选项卡找不到源代码。

我尝试下载一些插件,但它不起作用。 请帮忙,在此先感谢。

(注意:我使用的是 eclipse mars,版本 2.7.2,操作系统是 ubuntu 16.04 LTS)

【问题讨论】:

  • 请建议我可以下载的网址或插件名称。

标签: eclipse mapreduce eclipse-plugin ubuntu-16.04 hadoop2


【解决方案1】:

在 Eclipse 中设置 Map-Reduce 项目的最佳方式是使用 Maven。

  1. 首先,在 Eclipse 中设置一个 Maven 项目。点击此链接:https://wiki.jasig.org/display/UPM32/Creating+a+Simple+Maven+Project

2.接下来,使用以下标签更新您的 maven 项目的 pom.xml 文件。您可以根据需要更改 Hadoop 相关工件的版本标签(根据您的问题为 2.7.2)。确保在系统环境变量中设置了 JAVA_HOME。

<dependencies>
     <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
           <groupId>jdk.tools</groupId>
           <artifactId>jdk.tools</artifactId>
           <scope>system</scope>
           <version>1.8</version>//1.7 if you are using jdk 7
           <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-mapreduce-client-core</artifactId>
            <version>2.7.3</version>
        </dependency>
         <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.3</version>
        </dependency>
</dependencies>
  1. 右键单击您的 Eclipse 项目转到 Maven -> 单击更新项目 并等待一段时间。它将下载所有依赖 jar 以执行 Hadoop 客户端。

4.现在,当您编写 Mapreduce 代码并尝试查看任何类或方法(在您的情况下为作业)的源代码时,Eclipse 不应抱怨“未使用附加源选项卡找到源代码”。你应该可以看到源代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    相关资源
    最近更新 更多