wax_lyrical
wax_lyrical

Reputation: 942

Maven-Shade MySQL classnotfound

I'm trying to use Maven Shade to build an Uber Jar. Everything is working, it builds makes the uber jar, which I'm running from a BAT file: non database stuff runs fine, but for some reason, MySQL-Connector is not being found on the classpath.

2014-09-08 17:14:00 DEBUG DatabaseConnectionFactory:47 - Creating a new database connection
2014-09-08 17:14:00 ERROR DatabaseConnectionFactory:53 - java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/myDB?user=root&password=

The maven plugins are located in my parent POM, and the dependencies are in the child poms, ( though I've tried putting the plugins in the DB module POM too, to no avail.)

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.32</version>
</dependency>

In seeking a solution, I've adding -cp to the downloaded jar on the command line, but I can't get the connector found! The whole program works in my IDE fine, no issues.

I've read a couple of other posts involving Shade, from which I never found a clear enough ( clear enough for me ( no comments please) answer!) The answers usually stipulated using assembly plugin. However, I'd like to stick with Shade as it makes everything simple.

I've added a cut down POM below, and am hoping someone can help me out!

Many thanks!

               <execution>
                    <id>myClient</id>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <outputFile>C:\Dev\myJar.jar</outputFile>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>myapp.ClientStart</mainClass>
                            </transformer>
                        </transformers>

                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                    <exclude>properties/**</exclude>
                                    <exclude>images/**</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>

Upvotes: 2

Views: 1964

Answers (1)

Harald Wellmann
Harald Wellmann

Reputation: 12885

Check if your shaded JAR contains a resource META-INF/services/java.sql.Driver with contents

com.mysql.jdbc.Driver

If it doesn't, there might be some other JDBC driver in your dependencies which superseded the MySQL resource.

Upvotes: 3

Related Questions