title: Spark Java Appilcation : java.lang.ClassNotFoundException
body: <p>I've created a Apache Spark application using Java. All it does is counting the lines containing the "spark" word 1000 times.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class Example1 {
      public static void main(String[] args) {
          String logfile = args[0];
          try{
              SparkConf conf = new SparkConf();
              conf.setAppName("Sample");
              conf.setMaster("spark://&lt;master&gt;:7077");
              conf.set("spark.executor.memory", "1g");
              JavaSparkContext sc = new JavaSparkContext(conf);
              JavaRDD&lt;String&gt; logData = sc.textFile(logfile).cache();
              long count = 0;
              for(int i=0; i&lt;=1000; i++){
                  count += logData.filter(new Function&lt;String, Boolean&gt;(){
                      public Boolean call(String s){
                          if (s.toLowerCase().contains("spark"))
                              return true;
                          else
                              return false;
                      }
                  }).count();
              }
          }
          catch(Exception ex){
              System.out.println(ex.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>When I perform a debug in Eclipse IDE, I am encountering <code>java.lang.ClassNotFoundException</code>:</p>
  
  <pre><code>WARN scheduler.TaskSetManager: Loss was due to java.lang.ClassNotFoundException
  java.lang.ClassNotFoundException: org.spark.java.examples.Example1$1
  at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:270)
  </code></pre>
  
  <p>I also tried to deploy this inside the cluster using <code>spark-submit</code>, but still, the same exception was encountered. Here's a portion of the stacktrace:</p>
  
  <pre><code>ERROR Executor: Exception in task ID 4
  java.lang.ClassNotFoundException: org.spark.java.examples.Example1$1
  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:425)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  at java.lang.Class.forName0(Native Method)
  </code></pre>
  
  <p>Any ideas on how to resolve this? Thanks in advance!</p>