title: Unable to load class: com.mysql.jdbc.Driver error in Maven Dropwizard project
body: <p>I'm new to Maven and to get a hang of it, I've tried creating a Dropwizard project and tried adding connection to mySQL database. I've done the following in my yml file -</p>
  
  <p>a)yml -</p>
  
  <pre><code># Database settings.
  database:
      # the name of the JDBC driver, mysql in our case
      driverClass: com.mysql.jdbc.Driver
      # the username
      user: root
      # the password
      password: drivedge12
      # the JDBC URL; the database is called Hotel2
      url: jdbc:mysql://localhost:3306/hotelmanagement
  </code></pre>
  
  <p>And the following in my xml file -
  b)pom.xml -</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;prerequisites&gt;
          &lt;maven&gt;3.0.0&lt;/maven&gt;
      &lt;/prerequisites&gt;
  
      &lt;artifactId&gt;dropwizard-example&lt;/artifactId&gt;
      &lt;version&gt;1.1.0-SNAPSHOT&lt;/version&gt;
      &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
      &lt;name&gt;Dropwizard Example Application&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&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;!-- You'll probably want to remove this for your project. We're just using it here
               so that dropwizard-example doesn't get deployed as a library. --&gt;
          &lt;maven.deploy.skip&gt;true&lt;/maven.deploy.skip&gt;
          &lt;!-- You'll probably want to remove this for your project. We'Re just using it here
               so that dropwizard-example site doesn't get staged and deployed. --&gt;
          &lt;maven.site.skip&gt;true&lt;/maven.site.skip&gt;
          &lt;maven.site.deploy.skip&gt;true&lt;/maven.site.deploy.skip&gt;
      &lt;/properties&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;sonatype-nexus-snapshots&lt;/id&gt;
              &lt;name&gt;Sonatype Nexus Snapshots&lt;/name&gt;
              &lt;url&gt;http://oss.sonatype.org/content/repositories/snapshots&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&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.37&lt;/version&gt;
         &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
                  &lt;artifactId&gt;dropwizard-bom&lt;/artifactId&gt;
                  &lt;version&gt;${project.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-auth&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-assets&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-http2&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-hibernate&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-migrations&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-views-freemarker&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-views-mustache&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-metrics-graphite&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
              &lt;artifactId&gt;dropwizard-testing&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-test-framework-provider-inmemory&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                      &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;junit&lt;/groupId&gt;
                      &lt;artifactId&gt;junit&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-test-framework-provider-grizzly2&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                      &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;junit&lt;/groupId&gt;
                      &lt;artifactId&gt;junit&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&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-clean-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.6.1&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
    &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
    &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;9.4.2-SNAPSHOT&lt;/version&gt;
  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&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;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.7&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.4.1&lt;/version&gt;
                  &lt;/plugin&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.6.0&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.4&lt;/version&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;version&gt;2.6&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.4.3&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.8.2&lt;/version&gt;
                  &lt;/plugin&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-site-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.4&lt;/version&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;enforce&lt;/id&gt;
                          &lt;configuration&gt;
                              &lt;rules&gt;
                                  &lt;DependencyConvergence /&gt;
                              &lt;/rules&gt;
                          &lt;/configuration&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;enforce&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;attach-sources&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;jar&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&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;addDefaultImplementationEntries&gt;true&lt;/addDefaultImplementationEntries&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;createDependencyReducedPom&gt;true&lt;/createDependencyReducedPom&gt;
                      &lt;filters&gt;
                          &lt;filter&gt;
                              &lt;artifact&gt;*:*&lt;/artifact&gt;
                              &lt;excludes&gt;
                                  &lt;exclude&gt;META-INF/*.SF&lt;/exclude&gt;
                                  &lt;exclude&gt;META-INF/*.DSA&lt;/exclude&gt;
                                  &lt;exclude&gt;META-INF/*.RSA&lt;/exclude&gt;
                              &lt;/excludes&gt;
                          &lt;/filter&gt;
                      &lt;/filters&gt;
                      &lt;transformers&gt;
                          &lt;transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /&gt;
                          &lt;transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
                              &lt;mainClass&gt;com.example.helloworld.HelloWorldApplication&lt;/mainClass&gt;
                          &lt;/transformer&gt;
                      &lt;/transformers&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;shade&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;dev&lt;/id&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;phase&gt;none&lt;/phase&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Yet I keep getting the following error, while trying to run as a Java Application - </p>
  
  <pre><code>WARN  [2017-02-16 04:44:52,491] org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata : Unable to load class: com.mysql.jdbc.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader@73d16e93;ClassLoader:sun.misc.Launcher$AppClassLoader@73d16e93
  Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
  </code></pre>
  
  <p>Can anyone let me know where is that I'm going here and what I need to do to rectify it?</p>