java编译不生成.jar

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

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

package org.myorg;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

  public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
  private final static IntWritable one = new IntWritable(1);
  private Text word = new Text();

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

 public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

 public void reduce(Text key, Iterator<IntWritable> values, Context context)
         throws IOException, InterruptedException {
     int sum = 0;
     while (values.hasNext()) {
         sum += values.next().get();
     }
     context.write(key, new IntWritable(sum));
  }
}

public static void main(String[] args) throws Exception {
  Configuration conf = new Configuration();
  Job job = new Job(conf, "wordcount");

  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);

  job.setMapperClass(Map.class);
  job.setReducerClass(Reduce.class);

  job.setInputFormatClass(TextInputFormat.class);
  job.setOutputFormatClass(TextOutputFormat.class);

  FileInputFormat.addInputPath(job, new Path(args[0]));
  FileOutputFormat.setOutputPath(job, new Path(args[1]));

  job.waitForCompletion(true);
  }

}
sycxhyv7

sycxhyv71#

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

相关问题