title: ClassNotFoundException with Apache Spark and assembled Jar
body: <p>I'm trying to run a Java project that uses Apache Spark. I read my data from CSV files into a dataset. If I run the code from Eclipse, everyhing works fine. I configured the project such that a single jar with all dependencies is made.
  If I run the jar file using <code>java -jar ...</code>, this happens:</p>
  
  <pre><code>exception in thread "main" java.lang.ClassNotFoundException: Failed to find data source: csv. Please find packages at http://spark.apache.org/third-party-projects.html
      at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:635)
      at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:190)
      at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:594)
      at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:473)
      at access.DocumentsSparkAccess.getInstance(DocumentsSparkAccess.java:32)
      at process.TopicModelCreator.&lt;init&gt;(TopicModelCreator.java:38)
      at main.Main.createTopicModel(Main.java:56)
      at main.Main.main(Main.java:37)
  Caused by: java.lang.ClassNotFoundException: csv.DefaultSource
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$23$$anonfun$apply$15.apply(DataSource.scala:618)
      at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$23$$anonfun$apply$15.apply(DataSource.scala:618)
      at scala.util.Try$.apply(Try.scala:192)
      at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$23.apply(DataSource.scala:618)
      at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$23.apply(DataSource.scala:618)
      at scala.util.Try.orElse(Try.scala:84)
      at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:618)
  </code></pre>
  
  <p>I use the following versions:</p>
  
  <ul>
  <li>Java 1.8</li>
  <li>Apache Spark 2.3.0</li>
  </ul>
  
  <p>I use the Maven assembly plugin like this:</p>
  
  <pre><code>&lt;plugin&gt;
    &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
    &lt;version&gt;3.1.0&lt;/version&gt;
    &lt;configuration&gt;
      &lt;archive&gt;
        &lt;manifest&gt;
          &lt;mainClass&gt;main.Main&lt;/mainClass&gt;
        &lt;/manifest&gt;
      &lt;/archive&gt;
      &lt;descriptorRefs&gt;
        &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
      &lt;/descriptorRefs&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
      &lt;execution&gt;
        &lt;phase&gt;package&lt;/phase&gt;
        &lt;goals&gt;
          &lt;goal&gt;single&lt;/goal&gt;
        &lt;/goals&gt;
      &lt;/execution&gt;
    &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>The dependencies are included like this:</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
    &lt;artifactId&gt;spark-core_2.11&lt;/artifactId&gt;
    &lt;version&gt;2.3.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
    &lt;artifactId&gt;spark-mllib_2.11&lt;/artifactId&gt;
    &lt;version&gt;2.3.0&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Answer:</p>
  
  <p>This problem has been solved already for Parquet files:
  <a href="https://stackoverflow.com/questions/39455491/failed-to-find-data-source-parquet-when-making-a-fat-jar-with-maven">&quot;Failed to find data source: parquet&quot; when making a fat jar with maven</a>        </p>