选择“Artifacts”,点击“+”,选择“jar->from modules with dependencies”添加程序jar包
代码实例
[mw_shl_code=scala,true]package test
/**
* Created by zwx on 5/1/15.
*/
import scala.math.random
import org.apache.spark._
/** Computes an approximation to pi */
object SparkPi {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Spark Pi")
.setMaster("spark://10.0.5.217:7077")
.setJars(List("/home/zwx/IdeaProjects/FisrtScala/out/artifacts/FisrtScala_jar/FisrtScala.jar"))
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()
}[/mw_shl_code]