参考内容: http://blog.csdn.net/deng2012web/article/details/51931686java程序:package com.hq;import org.apache.hadoop.conf.Configuration;import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaPairRDD;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.api.java.JavaSparkContext;import org.apache.spark.api.java.function.FlatMapFunction;import org.apache.spark.api.java.function.Function2;import org.apache.spark.api.java.function.PairFunction;import scala.Tuple2;import java.util.Arrays;import java.util.Iterator;import java.util.List;import java.util.regex.Pattern;public final class JavaWordCount {  private static final Pattern SPACE = Pattern.compile(" ");  public static void main(String[] args) throws Exception {    if (args.length      System.err.println("Usage: JavaWordCount ");      System.exit(1);    }       Configuration conf = new Configuration();    conf.set("fs.defaultFS" output = counts.collect();    for (Tuple2 tuple : output) {      System.out.println(tuple._1() + ": " + tuple._2());    }    ctx.stop();  }}有关脚本:spark-submit --master spark://master:7077 --name WordCountByscala --class com.hq.WordCount --executor-memory 1G --total-executor-cores 2 jars/spark-wordcount-in-scala.jar hdfs://master:9000/user/word.txtspark-submit --master spark://master:7077 --name JavaWordCountByHQ --class com.hq.JavaWordCount --executor-memory 1G --total-executor-cores 2 jars/spark-wordcount-in-scala.jar hdfs://master:9000/user/word.txtspark-submit --master spark://192.168.0.76:7077 --name JavaWordCountByHQ --class com.hq.JavaWordCount --executor-memory 1G --total-executor-cores 2 spark-wordcount-in-scala.jar hdfs://192.168.0.76:9000/user/word.txtspark-submit --master spark://master --name JavaWordCountByHQ --class com.hq.JavaWordCount --executor-memory 1G --total-executor-cores 2 spark-wordcount-in-scala.jar hdfs://master:9000/user/word.txt
10-04 07:27