title: How to debug a scala based Spark program on Intellij IDEA
body: <p>I am currently building my development IDE using Intellij IDEA. I followed exactly the same way as <a href="http://spark.apache.org/docs/latest/quick-start.html" rel="noreferrer">http://spark.apache.org/docs/latest/quick-start.html</a></p>
  
  <p><strong>build.sbt file</strong></p>
  
  <pre><code>name := "Simple Project"
  
  version := "1.0"
  
  scalaVersion := "2.11.7"
  
   libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0"
  </code></pre>
  
  <p><strong>Sample Program File</strong></p>
  
  <pre><code>import org.apache.spark.SparkContext
  import org.apache.spark.SparkContext._
  import org.apache.spark.SparkConf
  
  object MySpark {
  
      def main(args: Array[String]){
          val logFile = "/IdeaProjects/hello/testfile.txt" 
          val conf = new SparkConf().setAppName("Simple Application")
          val sc = new SparkContext(conf)
          val logData = sc.textFile(logFile, 2).cache()
          val numAs = logData.filter(line =&gt; line.contains("a")).count()
          val numBs = logData.filter(line =&gt; line.contains("b")).count()
          println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
      }
  }
  </code></pre>
  
  <p>If I use command line:</p>
  
  <pre><code>sbt package
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>spark-submit --class "MySpark" --master local[4] target/scala-2.11/myspark_2.11-1.0.jar
  </code></pre>
  
  <p>I am able to generate jar package and spark runs well.</p>
  
  <p>However, I want to use Intellij IDEA to debug the program in the IDE. How can I setup the configuration, so that if I click "debug", it will automatically generate the jar package and automatically launch the task by executing "spark-submit-" command line. </p>
  
  <p>I just want everything could be simple as "one click" on the debug button in Intellij IDEA. </p>
  
  <p>Thanks.</p>