title: Error Running Cassandra from Spark in Java - NoClassDefFoundError at org.apache.spark.sql.catalyst
body: <p>I am using Cassandra 3.0.3, Spark 1.6.0 and trying to run by combining code from the old documentation in <a href="http://www.datastax.com/dev/blog/accessing-cassandra-from-spark-in-java" rel="nofollow">http://www.datastax.com/dev/blog/accessing-cassandra-from-spark-in-java</a> and the new one in <a href="https://github.com/datastax/spark-cassandra-connector/blob/master/doc/7_java_api.md" rel="nofollow">https://github.com/datastax/spark-cassandra-connector/blob/master/doc/7_java_api.md</a>.</p>
  
  <p>Here is my pom.xml file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
   &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
   &lt;groupId&gt;muhrafifm&lt;/groupId&gt;
   &lt;artifactId&gt;spark-cass-twitterdw&lt;/artifactId&gt;
   &lt;version&gt;1.0&lt;/version&gt;
   &lt;packaging&gt;jar&lt;/packaging&gt;
   &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.0&lt;/version&gt;
            &lt;configuration&gt;
                &lt;source&gt;1.7&lt;/source&gt;
                &lt;target&gt;1.7&lt;/target&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;        
      &lt;dependency&gt;
          &lt;groupId&gt;com.datastax.cassandra&lt;/groupId&gt;
          &lt;artifactId&gt;cassandra-driver-core&lt;/artifactId&gt;
          &lt;version&gt;3.0.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.googlecode.json-simple&lt;/groupId&gt;
          &lt;artifactId&gt;json-simple&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;    
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.datastax.spark&lt;/groupId&gt;
          &lt;artifactId&gt;spark-cassandra-connector_2.10&lt;/artifactId&gt;
          &lt;version&gt;1.6.0-M1&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.datastax.spark&lt;/groupId&gt;
          &lt;artifactId&gt;spark-cassandra-connector-java_2.10&lt;/artifactId&gt;
          &lt;version&gt;1.6.0-M1&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
          &lt;artifactId&gt;spark-core_2.10&lt;/artifactId&gt;
          &lt;version&gt;1.6.0&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
          &lt;artifactId&gt;spark-streaming_2.10&lt;/artifactId&gt;
          &lt;version&gt;1.6.0&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.thrift&lt;/groupId&gt;
          &lt;artifactId&gt;libthrift&lt;/artifactId&gt;
          &lt;version&gt;0.9.1&lt;/version&gt;
       &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p></p>
  
  <p>The changes I made are basically in method javaFunction, and here is one of the method after I change the javaFunction according to the new documentation. I've also included <code>import static com.datastax.spark.connector.japi.CassandraJavaUtil.*;</code></p>
  
  <pre><code>private void generateData(JavaSparkContext sc) {
      CassandraConnector connector = CassandraConnector.apply(sc.getConf());
  
      // Prepare the schema
      try (Session session = connector.openSession()) {
          session.execute("DROP KEYSPACE IF EXISTS java_api");
          session.execute("CREATE KEYSPACE java_api WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
          session.execute("CREATE TABLE java_api.products (id INT PRIMARY KEY, name TEXT, parents LIST&lt;INT&gt;)");
          session.execute("CREATE TABLE java_api.sales (id UUID PRIMARY KEY, product INT, price DECIMAL)");
          session.execute("CREATE TABLE java_api.summaries (product INT PRIMARY KEY, summary DECIMAL)");
      }
  
      // Prepare the products hierarchy
      List&lt;Product&gt; products = Arrays.asList(
              new Product(0, "All products", Collections.&lt;Integer&gt;emptyList()),
              new Product(1, "Product A", Arrays.asList(0)),
              new Product(4, "Product A1", Arrays.asList(0, 1)),
              new Product(5, "Product A2", Arrays.asList(0, 1)),
              new Product(2, "Product B", Arrays.asList(0)),
              new Product(6, "Product B1", Arrays.asList(0, 2)),
              new Product(7, "Product B2", Arrays.asList(0, 2)),
              new Product(3, "Product C", Arrays.asList(0)),
              new Product(8, "Product C1", Arrays.asList(0, 3)),
              new Product(9, "Product C2", Arrays.asList(0, 3))
      );
  
      JavaRDD&lt;Product&gt; productsRDD = sc.parallelize(products);       
      javaFunctions(productsRDD).writerBuilder("java_api", "products", mapToRow(Product.class)).saveToCassandra();
  
      JavaRDD&lt;Sale&gt; salesRDD = productsRDD.filter(new Function&lt;Product, Boolean&gt;() {
          @Override
          public Boolean call(Product product) throws Exception {
              return product.getParents().size() == 2;
          }
      }).flatMap(new FlatMapFunction&lt;Product, Sale&gt;() {
          @Override
          public Iterable&lt;Sale&gt; call(Product product) throws Exception {
              Random random = new Random();
              List&lt;Sale&gt; sales = new ArrayList&lt;&gt;(1000);
              for (int i = 0; i &lt; 1000; i++) {
                  sales.add(new Sale(UUID.randomUUID(), product.getId(), BigDecimal.valueOf(random.nextDouble())));
              }
              return sales;
          }
      });
      javaFunctions(salesRDD).writerBuilder("java_api", "sales", mapToRow(Sale.class)).saveToCassandra();
  }
  </code></pre>
  
  <p>And here is the error that I got.</p>
  
  <pre><code>16/03/04 13:29:06 INFO Cluster: New Cassandra host /127.0.0.1:9042 added
  16/03/04 13:29:06 INFO CassandraConnector: Connected to Cassandra cluster: Test Cluster
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/sql/catalyst/package$ScalaReflectionLock$
      at org.apache.spark.sql.catalyst.ReflectionLock$.&lt;init&gt;(ReflectionLock.scala:5)
      at org.apache.spark.sql.catalyst.ReflectionLock$.&lt;clinit&gt;(ReflectionLock.scala)
      at com.datastax.spark.connector.mapper.ReflectionColumnMapper.&lt;init&gt;(ReflectionColumnMapper.scala:38)
      at com.datastax.spark.connector.mapper.JavaBeanColumnMapper.&lt;init&gt;(JavaBeanColumnMapper.scala:10)
      at com.datastax.spark.connector.util.JavaApiHelper$.javaBeanColumnMapper(JavaApiHelper.scala:93)
      at com.datastax.spark.connector.util.JavaApiHelper.javaBeanColumnMapper(JavaApiHelper.scala)
      at com.datastax.spark.connector.japi.CassandraJavaUtil.mapToRow(CassandraJavaUtil.java:1204)
      at com.datastax.spark.connector.japi.CassandraJavaUtil.mapToRow(CassandraJavaUtil.java:1222)
      at muhrafifm.spark.cass.twitterdw.Demo.generateData(Demo.java:69)
      at muhrafifm.spark.cass.twitterdw.Demo.run(Demo.java:35)
      at muhrafifm.spark.cass.twitterdw.Demo.main(Demo.java:181)
  Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.catalyst.package$ScalaReflectionLock$
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 11 more
  16/03/04 13:29:40 INFO CassandraConnector: Disconnected from Cassandra cluster: Test Cluster
  16/03/04 13:29:41 INFO SparkContext: Invoking stop() from shutdown hook
  16/03/04 13:29:41 INFO SparkUI: Stopped Spark web UI at http://10.144.233.28:4040
  16/03/04 13:29:41 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
  16/03/04 13:29:42 INFO MemoryStore: MemoryStore cleared
  16/03/04 13:29:42 INFO BlockManager: BlockManager stopped
  16/03/04 13:29:42 INFO BlockManagerMaster: BlockManagerMaster stopped
  16/03/04 13:29:42 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
  16/03/04 13:29:42 INFO SparkContext: Successfully stopped SparkContext
  16/03/04 13:29:42 INFO ShutdownHookManager: Shutdown hook called
  16/03/04 13:29:42 INFO ShutdownHookManager: Deleting directory /tmp/spark-    16fd2ae2-b61b-4411-a776-1e578caabba6
  ------------------------------------------------------------------------
  BUILD FAILURE
  </code></pre>
  
  <p>Is there anything I did wrong? it seems like needing the package that I don't even use, is there anything to fix that? or should I use the previous version of the cassandra-spark-connector?</p>
  
  <p>Any response is appreciated, Thank you.</p>