java实现代码:
import org.apache.spark.api.java.JavaSparkContext; 2 /** 3 * spark测试 4 * Created by lxq on 2014/10/23. 5 */ 6 public final class Test { 7 public static void main(String[] args) throws Exception { 8 9 /**10 * 参数说明:11 * 1、URL:spark的Ip地址或是写成:spark://master:7077;看配置如何配了12 * 2、给该项目起的名字13 * 3、spark的安装路径14 * 4、需要引入的包15 */16 JavaSparkContext ctx = new JavaSparkContext("spark://URL:7077", "SparkTest",17 "~/spark-1.0.2",18 "lib/spark-assembly-1.0.2-hadoop2.2.0.jar");19 System.out.println(ctx.appName());20 }21 }
Scala实现代码:
import org.apache.spark.SparkContextimport org.apache.spark.mllib.classification.SVMWithSGDimport org.apache.spark.mllib.evaluation.BinaryClassificationMetricsimport org.apache.spark.mllib.util.MLUtilsobject Test { def main(args: Array[String]) { val sc = new SparkContext("spark://URL(master的ip或是直接master):7077", "WordCount", System.getenv("~/spark-1.0.2"), Seq(System.getenv("lib/spark-assembly-1.0.2-hadoop2.2.0.jar")))}