title: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver for Maven runnable jar
body: <p>I'm trying to create .jar file in my server(CentOS) using Maven. It is successfully compiling and generates the .jar file. But when I execute it, it shows the following error. This questions may look like "previously asked" but, I tried all the suggestions from here. What I believe is in my POM.xml have some issue, but I'm not able to find. If someone can verify the POM.xml it would be helpful.</p>
  
  <p>Command:</p>
  
  <pre><code>$ java -jar target/ListDescCrawler-1.1-SNAPSHOT.jar
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  </code></pre>
  
  <p>My POM.xml</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/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;edu.uci.ics.crawler4j&lt;/groupId&gt;
    &lt;artifactId&gt;ListDescCrawler&lt;/artifactId&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;version&gt;1.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;SanListDescCrawlerHandu&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
    &lt;build&gt;
        &lt;pluginManagement&gt;
          &lt;plugins&gt;
            &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.3&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;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;archive&gt;
                          &lt;manifest&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;mainClass&gt;edu.uci.ics.crawler4j.example.MainController&lt;/mainClass&gt;                         
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
        &lt;/pluginManagement&gt;
    &lt;/build&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.james&lt;/groupId&gt;
          &lt;artifactId&gt;apache-mime4j-core&lt;/artifactId&gt;
          &lt;version&gt;0.7&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.james&lt;/groupId&gt;
          &lt;artifactId&gt;apache-mime4j-dom&lt;/artifactId&gt;
          &lt;version&gt;0.7&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;asm&lt;/groupId&gt;
          &lt;artifactId&gt;asm&lt;/artifactId&gt;
          &lt;version&gt;3.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;de.l3s.boilerpipe&lt;/groupId&gt;
          &lt;artifactId&gt;boilerpipe&lt;/artifactId&gt;
          &lt;version&gt;1.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-codec&lt;/groupId&gt;
          &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
          &lt;version&gt;1.6&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-compress&lt;/artifactId&gt;
          &lt;version&gt;1.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;version&gt;1.1.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;fluent-hc&lt;/artifactId&gt;
          &lt;version&gt;4.3.6&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.geronimo.specs&lt;/groupId&gt;
          &lt;artifactId&gt;geronimo-stax-api_1.0_spec&lt;/artifactId&gt;
          &lt;version&gt;1.0.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
          &lt;version&gt;4.3.6&lt;/version&gt;
      &lt;/dependency&gt;   
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
          &lt;version&gt;4.3.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
          &lt;version&gt;4.3.6&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sleepycat&lt;/groupId&gt;
          &lt;artifactId&gt;je&lt;/artifactId&gt;
          &lt;version&gt;4.0.92&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jsoup&lt;/groupId&gt;
          &lt;artifactId&gt;jsoup&lt;/artifactId&gt;
          &lt;version&gt;1.8.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.17&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.drewnoakes&lt;/groupId&gt;
          &lt;artifactId&gt;metadata-extractor&lt;/artifactId&gt;
          &lt;version&gt;2.4.0-beta-1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.34&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.ccil.cowan.tagsoup&lt;/groupId&gt;
          &lt;artifactId&gt;tagsoup&lt;/artifactId&gt;
          &lt;version&gt;1.2.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.tika&lt;/groupId&gt;
          &lt;artifactId&gt;tika-app&lt;/artifactId&gt;
          &lt;version&gt;1.6&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The MANIFEST.MF file in the generated .jar file:</p>
  
  <pre><code>Manifest-Version: 1.0
  Archiver-Version: Plexus Archiver
  Created-By: Apache Maven
  Built-By: root
  Build-Jdk: 1.7.0_91
  Main-Class: edu.uci.ics.crawler4j.example.MainController
  Class-Path: apache-mime4j-core-0.7.jar apache-mime4j-dom-0.7.jar asm-3
   .1.jar boilerpipe-1.1.0.jar commons-codec-1.6.jar commons-compress-1.
   3.jar commons-logging-1.1.3.jar fluent-hc-4.3.6.jar geronimo-stax-api
   _1.0_spec-1.0.1.jar httpclient-4.3.6.jar httpcore-4.3.3.jar httpmime-
   4.3.6.jar je-4.0.92.jar jsoup-1.8.1.jar log4j-1.2.17.jar metadata-ext
   ractor-2.4.0-beta-1.jar tagsoup-1.2.1.jar tika-app-1.6.jar tika-parse
   rs-1.6.jar tika-core-1.6.jar vorbis-java-tika-0.6.jar netcdf-4.2.20.j
   ar unidataCommon-4.2.20.jar jcip-annotations-1.0.jar commons-httpclie
   nt-3.1.jar jmatio-1.0.jar xz-1.5.jar pdfbox-1.8.6.jar fontbox-1.8.6.j
   ar jempbox-1.8.6.jar bcmail-jdk15-1.45.jar bcprov-jdk15-1.45.jar poi-
   3.11-beta2.jar poi-scratchpad-3.11-beta2.jar poi-ooxml-3.11-beta2.jar
    poi-ooxml-schemas-3.11-beta2.jar xmlbeans-2.6.0.jar asm-debug-all-4.
   1.jar isoparser-1.0.2.jar aspectjrt-1.8.0.jar rome-1.0.jar jdom-1.0.j
   ar vorbis-java-core-0.6.jar juniversalchardet-1.0.3.jar jhighlight-1.
   0.jar java-libpst-0.8.1.jar tika-serialization-1.6.jar tika-xmp-1.6.j
   ar xmpcore-5.1.2.jar slf4j-log4j12-1.5.6.jar slf4j-api-1.5.6.jar gson
   -1.7.1.jar
  </code></pre>
  
  <p>Commands executed:</p>
  
  <pre><code> mvn clean compile
   mvn clean package
   java -jar target/ListDescCrawler-1.1-SNAPSHOT.jar
  </code></pre>
  
  <p>There are many library files are added to the project including mysql-connector-java-5.1.34.jar. But still the error is showing. I checked in SOF for a solution and tried many suggestions from here, but nothing fixed my issue.</p>
  
  <p>I checked MANIFEST.MF in the generated .jar file and it looks fine. </p>
  
  <p>Other points to note is, its working fine from Eclipse(without Maven)</p>
  
  <p>is there any mistake in my POM.xml?</p>
  
  <p>The suggestions I tried:</p>
  
  <ol>
  <li><p>dependency/scope I tried all the possible values</p></li>
  <li><p>Copied mysql-connector-java-5.1.34.jar in the lib folder and changed the POM.xml accordingly  </p></li>
  </ol>
  
  <p>and may other suggestions but nothing helped.</p>
  
  <p>At last the things started to work with the following POM.xml</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/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;edu.uci.ics.crawler4j&lt;/groupId&gt;
      &lt;artifactId&gt;ListDescCrawler&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;SanListDescCrawlerHandu&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;jdk.version&gt;1.7&lt;/jdk.version&gt;      
          &lt;junit.version&gt;4.11&lt;/junit.version&gt;
          &lt;apache-mime4j-core.version&gt;0.7&lt;/apache-mime4j-core.version&gt;
          &lt;apache-mime4j-dom.version&gt;0.7&lt;/apache-mime4j-dom.version&gt;
          &lt;asm.version&gt;3.1&lt;/asm.version&gt;
          &lt;boilerpipe.version&gt;1.1.0&lt;/boilerpipe.version&gt;
          &lt;commons-codec.version&gt;1.6&lt;/commons-codec.version&gt;
          &lt;commons-compress.version&gt;1.3&lt;/commons-compress.version&gt;
          &lt;commons-logging.version&gt;1.1.3&lt;/commons-logging.version&gt;
          &lt;fluent-hc.version&gt;4.3.6&lt;/fluent-hc.version&gt;
          &lt;geronimo-stax-api_1.0_spec.version&gt;1.0.1&lt;/geronimo-stax-api_1.0_spec.version&gt;
          &lt;httpclient.version&gt;4.3.6&lt;/httpclient.version&gt;
          &lt;httpcore.version&gt;4.3.3&lt;/httpcore.version&gt;
          &lt;httpmime.version&gt;4.3.6&lt;/httpmime.version&gt;
          &lt;je.version&gt;4.0.92&lt;/je.version&gt;
          &lt;jsoup.version&gt;1.8.1&lt;/jsoup.version&gt;
          &lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
          &lt;metadata-extractor.version&gt;2.4.0-beta-1&lt;/metadata-extractor.version&gt;
          &lt;mysql-connector-java.version&gt;5.1.34&lt;/mysql-connector-java.version&gt;
          &lt;tagsoup.version&gt;1.2.1&lt;/tagsoup.version&gt;
          &lt;tika-app.version&gt;1.6&lt;/tika-app.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;${junit.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.james&lt;/groupId&gt;
              &lt;artifactId&gt;apache-mime4j-core&lt;/artifactId&gt;
              &lt;version&gt;${apache-mime4j-core.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.james&lt;/groupId&gt;
              &lt;artifactId&gt;apache-mime4j-dom&lt;/artifactId&gt;
              &lt;version&gt;${apache-mime4j-dom.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;asm&lt;/groupId&gt;
              &lt;artifactId&gt;asm&lt;/artifactId&gt;
              &lt;version&gt;${asm.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;de.l3s.boilerpipe&lt;/groupId&gt;
              &lt;artifactId&gt;boilerpipe&lt;/artifactId&gt;
              &lt;version&gt;${boilerpipe.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-codec&lt;/groupId&gt;
              &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
              &lt;version&gt;${commons-codec.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-compress&lt;/artifactId&gt;
              &lt;version&gt;${commons-compress.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-logging&lt;/groupId&gt;
              &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
              &lt;version&gt;${commons-logging.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;fluent-hc&lt;/artifactId&gt;
              &lt;version&gt;${fluent-hc.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.geronimo.specs&lt;/groupId&gt;
              &lt;artifactId&gt;geronimo-stax-api_1.0_spec&lt;/artifactId&gt;
              &lt;version&gt;${geronimo-stax-api_1.0_spec.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
              &lt;version&gt;${httpclient.version}&lt;/version&gt;
          &lt;/dependency&gt;   
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
              &lt;version&gt;${httpcore.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
              &lt;version&gt;${httpmime.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sleepycat&lt;/groupId&gt;
              &lt;artifactId&gt;je&lt;/artifactId&gt;
              &lt;version&gt;${je.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jsoup&lt;/groupId&gt;
              &lt;artifactId&gt;jsoup&lt;/artifactId&gt;
              &lt;version&gt;${jsoup.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;${log4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.drewnoakes&lt;/groupId&gt;
              &lt;artifactId&gt;metadata-extractor&lt;/artifactId&gt;
              &lt;version&gt;${metadata-extractor.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;${mysql-connector-java.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.ccil.cowan.tagsoup&lt;/groupId&gt;
              &lt;artifactId&gt;tagsoup&lt;/artifactId&gt;
              &lt;version&gt;${tagsoup.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tika&lt;/groupId&gt;
              &lt;artifactId&gt;tika-app&lt;/artifactId&gt;
              &lt;version&gt;${tika-app.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;ListDescCrawler&lt;/finalName&gt;
          &lt;plugins&gt;
  
              &lt;!-- download source code in Eclipse, best practice --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.9&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                      &lt;downloadJavadocs&gt;false&lt;/downloadJavadocs&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;           
  
              &lt;!-- Set a compiler level --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${jdk.version}&lt;/source&gt;
                      &lt;target&gt;${jdk.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;!-- Maven Assembly Plugin --&gt;
              &lt;plugin&gt;
                &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                  &lt;descriptorRefs&gt;
                    &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                  &lt;/descriptorRefs&gt;
                  &lt;archive&gt;
                    &lt;manifest&gt;
                      &lt;mainClass&gt;edu.uci.ics.crawler4j.example.MainController&lt;/mainClass&gt;
                    &lt;/manifest&gt;
                  &lt;/archive&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;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>