zoukankan      html  css  js  c++  java
  • IDEA非sbt下spark开发

    • 创建非sbt的scala项目
    • 引入spark的jar包
    File->Project Structure->Libararies引用spark-assembly-1.5.2-hadoop2.6.0.jar
    • 编写代码
    import scala.math.random
    import org.apache.spark._
    /**
     * Created by code-pc on 16/3/2.
      */
    object test1 {
      def main(args: Array[String]) {
        val conf = new SparkConf().setAppName("Spark Pi").setMaster("local")
        val spark = new SparkContext(conf)
        val slices = if (args.length > 0) args(0).toInt else 2
        val n = 100000 * slices
        val count = spark.parallelize(1 to n, slices).map { i =>
          val x = random * 2 - 1
          val y = random * 2 - 1
          if (x*x + y*y < 1) 1 else 0
        }.reduce(_ + _)
        println("Pi is roughly " + 4.0 * count / n)
        spark.stop()
      }
    }
    • 编译jar包
    File -> Project Structure -> Artifacts  -> + -> Jars -> From moudles with dependencies
    菜单栏:build Artifacts
    • 运行
    ./spark-submit --class test1 --master local ~/IdeaProjects/test1/out/artifacts/Pi/test1.jar
  • 相关阅读:
    poj1182 食物链
    poj1611 The Suspects
    poj3436 Computer Factory
    (转) GPG入门教程
    cronolog安装配置
    RHCA-436-4 rhcs conga
    pxe引导gparted live万能分区
    linux下拔号pptp
    GNU parted简略用法
    hostapd故障解决(1.1,2.0,2.2)
  • 原文地址:https://www.cnblogs.com/ggzone/p/7512892.html
Copyright © 2011-2022 走看看