title: How to run a spark example program in Intellij IDEA
body: <p>First on the command line from the root of the downloaded spark project I ran </p>
  
  <pre><code>mvn package
  </code></pre>
  
  <p>It was successful. </p>
  
  <p>Then an intellij project was created by importing the spark pom.xml.  </p>
  
  <p>In the IDE the example class appears fine: all of the libraries are found. This can be viewed in the screenshot. </p>
  
  <p>However , when attempting to run the main() a ClassNotFoundException on SparkContext occurs.</p>
  
  <p>Why can Intellij not simply load and run this maven based scala program?  And what can be done as a workaround?</p>
  
  <p>As one can see below, the SparkContext is looking fine in the IDE: but then is not found when attempting to run:
  <img src="https://i.stack.imgur.com/MGjM4.png" alt="enter image description here"></p>
  
  <p>The test was run by right clicking inside main():</p>
  
  <p><img src="https://i.stack.imgur.com/qQ9ya.png" alt="enter image description here"></p>
  
  <p>..  and selecting Run GroupByTest</p>
  
  <p>It gives </p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/SparkContext
      at org.apache.spark.examples.GroupByTest$.main(GroupByTest.scala:36)
      at org.apache.spark.examples.GroupByTest.main(GroupByTest.scala)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.lang.ClassNotFoundException: org.apache.spark.SparkContext
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 7 more
  </code></pre>
  
  <p>Here is the run configuration:</p>
  
  <p><img src="https://i.stack.imgur.com/MBtkD.png" alt="enter image description here"></p>