title: Maven missing MySQL dependency
body: <p>I have a Maven project in Eclipse (using ubuntu) with a class dbtest that access my SQL table in MySQL where I am using Apache Maven 3.3.9 and Java 1.8.0_181.</p>
  
  <p>When I am running and compiling the code using Eclipse it is working good (I do have a database called acm with "root" as my username and password) but when I create a Jar using Maven command:</p>
  
  <blockquote>
    <p>mvn clean install</p>
  </blockquote>
  
  <p>and I compile it I get the following error:</p>
  
  <pre><code>java -cp target/maven-1.jar test.dbtest
  start
  Class-start
  java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/acm
  End main
  </code></pre>
  
  <p>I have followed <a href="https://stackoverflow.com/questions/1074869/find-oracle-jdbc-driver-in-maven-repository">https://stackoverflow.com/questions/1074869/find-oracle-jdbc-</a> and tried many options such as Peter Enis answer or adding compile scope to the dependency and none of them have solved the problem.
  Moreover, I have also downloaded the mysql-connector-java jar (I have tried many versions) and added it to the library path, and it won't help, so I added the extracted jar to the path and the problem remains.</p>
  
  <p>Below are the dbtest class and my POM file.</p>
  
  <pre><code>package test;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  public class dbtest  
  {
  public static void main(String[] args) throws SQLException 
  {
      try
      {
      System.out.println("start");
      //Class.forName("com.mysql.jdbc.Driver");//.newInstance();
      System.out.println("Class-start");
      Connection  connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/acm", "root", "root");
      System.out.println("connection");
      Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
      System.out.println("statement");
      String sql = "SELECT * FROM article_102 limit 4";
      ResultSet rs = statement.executeQuery(sql);
      System.out.println("article_id | publication_id");
      while (rs.next())
          System.out.println(rs.getString("article_id") + ", " + rs.getString("publication_id"));
      statement.close();
      connection.close();
      }//try
              catch(Exception e){ System. out.println(e.toString());}
      System.out.println("End main");
      }//main
  
  }
  
  &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;maven&lt;/groupId&gt;
    &lt;artifactId&gt;maven&lt;/artifactId&gt;
    &lt;version&gt;1&lt;/version&gt;
  
    &lt;name&gt;maven&lt;/name&gt;
    &lt;!-- FIXME change it to the project's website --&gt;
    &lt;url&gt;http://www.example.com&lt;/url&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;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;dependency&gt;
         &lt;groupId&gt;mysql&lt;/groupId&gt;
         &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
         &lt;version&gt;5.1.6&lt;/version&gt;
      &lt;/dependency&gt;
  
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;pluginManagement&gt;&lt;!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.0.0&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --&gt;
          &lt;plugin&gt;
        &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.0.2&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.7.0&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.20.1&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.0.2&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.5.2&lt;/version&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
            &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.8.2&lt;/version&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><em>Comment</em>, I am querious if I need this line <code>Class.forName("com.mysql.jdbc.Driver");//.newInstance();</code> I have left it as a comment (and when I use it I just get that java.lang.ClassNotFoundException: com.mysql.jdbc.Driver) because some say I should and others say it won't change.</p>