java编译不生成.jar

nkkqxpd9  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(496)

我创建了一个简单的'wordcount.java'文件来实现一个简单的hadoop程序,在编译时,它不会创建一个.jar文件。在创建的文件 WordCount.class , WordCount$Map.class ,和 WordCount$Reduce.class . 我在房间里看了看 WordCount.java 并且它确实包含一个 public static void main(String[] args) 例程,所以它应该创建一个.jar文件,对吗?
这是我在很长一段时间内第一次涉足java,所以java的编译方式很容易出错,但是考虑到下面的代码,它不应该在正确编译后给我一个.jar文件吗?

  1. package org.myorg;
  2. import java.io.IOException;
  3. import java.util.*;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.conf.*;
  6. import org.apache.hadoop.io.*;
  7. import org.apache.hadoop.mapreduce.*;
  8. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  9. import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
  10. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  12. public class WordCount {
  13. public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
  14. private final static IntWritable one = new IntWritable(1);
  15. private Text word = new Text();
  16. public void map(LongWritable key, Text value, Context context) throws IOException,
  17. InterruptedException {
  18. String line = value.toString();
  19. StringTokenizer tokenizer = new StringTokenizer(line);
  20. while (tokenizer.hasMoreTokens()) {
  21. word.set(tokenizer.nextToken());
  22. context.write(word, one);
  23. }
  24. }
  25. }
  26. public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
  27. public void reduce(Text key, Iterator<IntWritable> values, Context context)
  28. throws IOException, InterruptedException {
  29. int sum = 0;
  30. while (values.hasNext()) {
  31. sum += values.next().get();
  32. }
  33. context.write(key, new IntWritable(sum));
  34. }
  35. }
  36. public static void main(String[] args) throws Exception {
  37. Configuration conf = new Configuration();
  38. Job job = new Job(conf, "wordcount");
  39. job.setOutputKeyClass(Text.class);
  40. job.setOutputValueClass(IntWritable.class);
  41. job.setMapperClass(Map.class);
  42. job.setReducerClass(Reduce.class);
  43. job.setInputFormatClass(TextInputFormat.class);
  44. job.setOutputFormatClass(TextOutputFormat.class);
  45. FileInputFormat.addInputPath(job, new Path(args[0]));
  46. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  47. job.waitForCompletion(true);
  48. }
  49. }
sycxhyv7

sycxhyv71#

我创建了一个简单的'wordcount.java'文件来实现一个简单的hadoop程序,在编译时,它不会创建一个.jar文件。
不,不会的。汇编输出 .java 文件(带 javac )是一个 .class 文件夹。
然后使用 jar 工具创建一个jar文件,其中包含这些类文件和您需要的任何其他资源。

相关问题