【问题标题】:Executing a jar through ant clean dist- appears under different name?通过 ant clean dist- 执行 jar 以不同的名称出现?
【发布时间】:2015-01-04 15:16:21
【问题描述】:

我正在使用 hadoop,需要从 /src 文件中的所有类组合创建一个 .jar 文件。每次我尝试创建它时,它都会出现在 WordCount.jar 而不是 Twitter.jar 下,我在下面的代码中已经说过:

import java.util.Arrays;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class Twitter {
    public static void runJob(String[] input, String output) throws Exception {
        Configuration conf = new Configuration();
        Job job = new Job(conf);
        job.setJarByClass(Twitter.class);
        job.setReducerClass(TwitterReducer.class);
        job.setMapperClass(TwitterMapper.class);
   
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);
        Path outputPath = new Path(output);
        FileInputFormat.setInputPaths(job, StringUtils.join(input, ","));
        FileOutputFormat.setOutputPath(job, outputPath);
        outputPath.getFileSystem(conf).delete(outputPath, true);
        job.waitForCompletion(true);
        }
    public static void main(String[] args) throws Exception {
        runJob(Arrays.copyOfRange(args, 0, args.length - 1), args[args.length - 1]);
    }
}
因此我不确定出了什么问题? .jar 本身中的文件与 /src 文件夹中的文件完全相同。

【问题讨论】:

  • 你的类被称为Twitter 但这并不意味着你的.jar 必须有这个名字....jar 名字可能是在build.xml 的jar 创建任务中定义的.可以分享一下吗?

标签: java hadoop ant jar build.xml


【解决方案1】:

Jar 文件的名称与其中的类名称无关。您需要检查 Ant 构建文件,特别是创建 jar 的目标。创建 Jar 文件的 Ant 任务通常是 jar 任务,文件名可以通过 destfile 属性指定。

【讨论】:

  • 不知道这一点,因为这是我第一次使用此类文件!成功了,谢谢!
猜你喜欢
  • 2021-07-19
  • 2013-09-07
  • 1970-01-01
  • 2017-10-14
  • 2019-05-11
  • 2021-03-20
  • 2013-11-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多