gpt4 book ai didi

Java编译不产生.jar

转载 作者:可可西里 更新时间:2023-11-01 16:26:07 26 4
gpt4 key购买 nike

我已经创建了简单的“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com