Java编译不产生.jar

标签 java hadoop jar compilation

我已经创建了简单的“WordCount.java”文件来实现一个简单的 hadoop 程序,并且在编译时,它不会创建一个 .jar 文件。在 WordCount.classWordCount$Map.classWordCount$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);
  }

}

最佳答案

I have created the simple 'WordCount.java' file for implementing a simple hadoop program and upon compilation, it does not create a .jar file.

不,不会。 .java 文件(使用javac)编译的输出是.class 文件的集合。

然后您使用 jar 工具创建一个包含这些类文件和您需要的任何其他资源的 jar 文件。

关于Java编译不产生.jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26724228/

相关文章:

java - 如何在新的 Java 对象中使用日期类型?

java - 特定的java方法返回空指针异常

json - 如何加载在HIVE中压缩的json snappy

java - Avro Schema Evolution With GenericData.Record - Mapreduce 过程

java - 为什么 Eclipse 将我的整个项目导出为可运行的 JAR 文件?

JAVA,批处理文件错误

java - 如何使用 Java 获取 Ubuntu 版本?

java - Spring : Spring scheduler with fixed-rate param work incorrectly

hadoop - 如何获取运行hadoop hdfs命令时调用的Java类的列表?

java - 如何为 Selenium 测试创建兼容的 JAR 文件?