title: Maven with Spark, execution for Spark classes
body: <p>I have the second question to my <a href="https://stackoverflow.com/questions/33348156/maven-with-spark">Maven-Spark problem</a>. I can now compile all classes and also execute non-Spark classes. By the execution of some spark-class I have the next error message:</p>
  
  <pre><code>Error: A JNI error has occurred, please check your installation and try again
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/mllib/linalg/DenseMatrix
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
      at java.lang.Class.getMethod0(Class.java:3018)
      at java.lang.Class.getMethod(Class.java:1784)
      at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
  Caused by: java.lang.ClassNotFoundException: org.apache.spark.mllib.linalg.DenseMatrix
      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)
      ... 7 more
  </code></pre>
  
  <p>Obviously the Java doesn't find the package of Spark. I suppose that I execute my Spark file in the wrong place, where my Spark installation is unvisible...
  I also have found the <a href="https://stackoverflow.com/questions/28922512/how-to-resolve-this-jni-error-when-trying-to-run-lwjgl-hello-world">similar topics</a> by SE. After that I have understood that I need to specify the CLASSPATH in my .jar file. Usually I create my .jar file with the command:</p>
  
  <pre><code>mvn package
  </code></pre>
  
  <p>My question is, how I can specify the CLASSPATH for my .jar explicitly (for several Spark classes)? Thank you for you time.</p>
  
  <p>Additional:</p>
  
  <p>my pom.xml file </p>
  
  <pre><code>&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;Prototype&lt;/groupId&gt;
    &lt;artifactId&gt;TestMaven&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
  
    &lt;name&gt;Test&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
     &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
     &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
    &lt;/properties&gt;
  
  
   &lt;dependencies&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.4.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.10&lt;/artifactId&gt;
          &lt;version&gt;1.4.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.databricks&lt;/groupId&gt;
          &lt;artifactId&gt;spark-csv_2.10&lt;/artifactId&gt;
          &lt;version&gt;1.0.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sparkjava&lt;/groupId&gt;
          &lt;artifactId&gt;spark-core&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-math3&lt;/artifactId&gt;
          &lt;version&gt;3.5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sparkjava&lt;/groupId&gt;
          &lt;artifactId&gt;spark-template-freemarker&lt;/artifactId&gt;
          &lt;version&gt;2.0.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
          &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.11&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Update:</strong> I have found a solution and can execute my Spark programm regarding <a href="http://spark.apache.org/docs/latest/quick-start.html#standalone-applications" rel="nofollow noreferrer">spark documentation</a></p>