gpt4 book ai didi

java - ClassNotFoundException : com. mysql.jdbc.jdbc2.optional.MysqlDataSource 错误

转载 作者:行者123 更新时间:2023-11-29 01:08:35 35 4
gpt4 key购买 nike

我在项目中使用 Hikari 库进行 MySQL 连接。当我尝试运行该程序时,出现 ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource 错误。我认为我必须在我的项目中包含 mysql-connector 库。

这是我的 pom.xml

    <dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.1-GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.0.Beta3</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<finalName>GridControl</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>net.thegridmc.control.GridControl</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>mysql:*</include>
<include>org.slf4j:*</include>
<include>com.zaxxer:*</include>
<include>org.javassist:javassist</include>
<include>io.netty:netty-all</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

jar 构建成功,但仍然出现错误。非常感谢任何帮助。谢谢。

最佳答案

尝试 com.mysql.cj.jdbc.MysqlDataSource。它适用于

mysql-connector-java 6.0.4

关于java - ClassNotFoundException : com. mysql.jdbc.jdbc2.optional.MysqlDataSource 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27785324/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com