Java Vert.x JDBC client runtime load error: Could not load driverClass com.mysql.cj.jdbc.Driver java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

50 views
Skip to first unread message

Kok How Teh

unread,
Jul 2, 2020, 5:37:10 AM7/2/20
to vert.x
I have the following dependecies:
```
<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-jdbc-client</artifactId>
  <version>3.9.1</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.20</version>
    <scope>runtime</scope>
</dependency>
```
Running my application using vertx CLI bumps into "Could not load driverClass com.mysql.cj.jdbc.Driver java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver" exception while running it with "java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -jar target/restapi-1.0-fat.jar" is OK. What do I miss? Thanks.

Tuhin Subhra Mandal

unread,
Jul 2, 2020, 6:06:22 AM7/2/20
to vert.x
This should not a problem, may be you can try changing the order.Dependencies look fine. It works for me
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
    <version>8.0.17</version>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-mysql-client</artifactId>
<version>3.9.0</version>
</dependency>

Kok How Teh

unread,
Jul 2, 2020, 7:02:24 AM7/2/20
to vert.x
No, it doesn't work.

Tuhin Subhra Mandal

unread,
Jul 2, 2020, 7:04:16 AM7/2/20
to vert.x
Can you post the build section of your pom file 

Kok How Teh

unread,
Jul 2, 2020, 7:09:44 AM7/2/20
to vert.x
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>io.vertx.core.Launcher</Main-Class>
                                        <Main-Verticle>com.restapi.vertx.Launcher</Main-Verticle>
                                    </manifestEntries>
                                </transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
          </transformer>                                
                            </transformers>
                            <artifactSet/>
                                    <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
                        </configuration>
                    </execution>
                </executions>
</plugin>
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
            <argLine>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true</argLine>
            </configuration>
        </plugin>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M4</version>
            </plugin>
</plugins>
</build>

Thomas SEGISMONT

unread,
Jul 2, 2020, 8:08:57 AM7/2/20
to vert.x
On GH you said in a comment that it actually works with the fat JAR but does not with vertx run

vertx run com.restapi.vertx.Launcher -cp target/*

It seems to me the classpath argument is incorrect, the JVM won't load just anything recursively in the target folder.
You need to provide a set of locations: the directory where your project classes and resources are, the directory where the dependencies are


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/815941a4-597b-46a0-9fd3-db577118ff9co%40googlegroups.com.

Kok How Teh

unread,
Jul 2, 2020, 8:11:56 AM7/2/20
to vert.x
I don't think so! Why only this particular dependency doesn't work while others don't have any problem to load at all!?!
To unsubscribe from this group and stop receiving emails from it, send an email to ve...@googlegroups.com.

Thomas SEGISMONT

unread,
Jul 2, 2020, 10:43:43 AM7/2/20
to vert.x
The CLI loads the Vert.x stack deps already (plus their dependencies for example Netty).

In your verticle code the only thing which does not come from the stack at this point are the JDBC driver classes.

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/da74a58d-c56c-4526-8e04-033299898c8eo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages