• Linux下编译java并生成jar包


    下面是WordCount.java类
    1. package com.ll;
    2. import java.io.IOException;
    3. import java.util.Iterator;
    4. import java.util.StringTokenizer;
    5. import org.apache.hadoop.fs.Path;
    6. import org.apache.hadoop.io.IntWritable;
    7. import org.apache.hadoop.io.LongWritable;
    8. import org.apache.hadoop.io.Text;
    9. import org.apache.hadoop.mapred.FileInputFormat;
    10. import org.apache.hadoop.mapred.FileOutputFormat;
    11. import org.apache.hadoop.mapred.JobClient;
    12. import org.apache.hadoop.mapred.JobConf;
    13. import org.apache.hadoop.mapred.MapReduceBase;
    14. import org.apache.hadoop.mapred.Mapper;
    15. import org.apache.hadoop.mapred.OutputCollector;
    16. import org.apache.hadoop.mapred.Reducer;
    17. import org.apache.hadoop.mapred.Reporter;
    18. import org.apache.hadoop.mapred.TextInputFormat;
    19. import org.apache.hadoop.mapred.TextOutputFormat;
    20. public class WordCount {
    21. public static class Map extends MapReduceBase implements
    22. Mapper<LongWritable, Text, Text, IntWritable> {
    23. private final static IntWritable one = new IntWritable(1);
    24. private Text word = new Text();
    25. public void map(LongWritable key, Text value,
    26. OutputCollector<Text, IntWritable> output, Reporter reporter)
    27. throws IOException {
    28. String line = value.toString();
    29. StringTokenizer tokenizer = new StringTokenizer(line);
    30. while (tokenizer.hasMoreTokens()) {
    31. word.set(tokenizer.nextToken());
    32. output.collect(word, one);
    33. }
    34. }
    35. }
    36. public static class Reduce extends MapReduceBase implements
    37. Reducer<Text, IntWritable, Text, IntWritable> {
    38. public void reduce(Text key, Iterator<IntWritable> values,
    39. OutputCollector<Text, IntWritable> output, Reporter reporter)
    40. throws IOException {
    41. int sum = 0;
    42. while (values.hasNext()) {
    43. sum += values.next().get();
    44. }
    45. output.collect(key, new IntWritable(sum));
    46. }
    47. }
    48. public static void main(String[] args) throws Exception {
    49. JobConf conf = new JobConf(WordCount.class);
    50. conf.setJobName("wordcount");
    51. conf.setOutputKeyClass(Text.class);
    52. conf.setOutputValueClass(IntWritable.class);
    53. conf.setMapperClass(Map.class);
    54. conf.setCombinerClass(Reduce.class);
    55. conf.setReducerClass(Reduce.class);
    56. conf.setInputFormat(TextInputFormat.class);
    57. conf.setOutputFormat(TextOutputFormat.class);
    58. FileInputFormat.setInputPaths(conf, new Path(args[0]));
    59. FileOutputFormat.setOutputPath(conf, new Path(args[1]));
    60. JobClient.runJob(conf);
    61. }
    62. }

    使用Linux命令行编译java代码,并生成jar包
    1. mkdir wordcount_classes
    2. javac -classpath ${HADOOP_HOME}/hadoop-${HADOOP_VERSION}-core.jar -d wordcount_classes/ WordCount.java
    3. jar -cvf /usr/joe/wordcount121.jar -C wordcount_classes/ .
    说明:
    • javac :用于编译java--->class文件;
    • -classpath:后面指定依赖的jara包存储的位置;
    • -d:指定输出目录;








  • 相关阅读:
    第六周学习进度总结
    构建之法阅读笔记03
    文件操作
    数组相关
    compareTo
    我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 比如n=3时,2*3的矩形块有3种覆盖方法:
    从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行
    整数中1出现的次数
    Java泛型(看着好有用)
    输入一个整数,输出该数32位二进制表示中1的个数。其中负数用补码表示。
  • 原文地址:https://www.cnblogs.com/ssslinppp/p/5942729.html
Copyright © 2020-2023  润新知