尝试连接到mysql时出现此异常!
请不要将此标记为重复,我在我发现的每个帖子中尝试了所有内容,但没有任何帮助。
不使用DataSources也无济于事! 这是我的JTS3Servermod插件的一部分。
线程“Soulsbot”中的异常java.lang.NoClassDefFoundError: COM / MySQL的/ JDBC / JDBC2 /可选择的/ MysqlDataSource
错误位于代码的第一行
我已经安装了Drivers etc,在eclipse中正确地将最新的库添加到了我的Workspace。
我在Debian8上运行它。在另一个使用插口的用户上,它起作用了。
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setServerName(host);
connection = dataSource.getConnection();
完整的错误消息:
Exception in thread "Soulsbot" java.lang.NoClassDefFoundError: com/mysql/jdbc/jdbc2/optional/MysqlDataSource
at net.mysticsouls.TeamSpeakBot.utils.NameUUIDUtils.connect(NameUUIDUtils.java:36)
at net.mysticsouls.TeamSpeakBot.utils.Updater.start(Updater.java:11)
at net.mysticsouls.TeamSpeakBot.TeamSpeakBot.activate(TeamSpeakBot.java:45)
at de.stefan1200.jts3servermod.JTS3ServerMod.e(Unknown Source)
at de.stefan1200.jts3servermod.JTS3ServerMod.b(Unknown Source)
at de.stefan1200.jts3servermod.i.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
来自Maven的pom.xml:
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>TeamSpeakBotMaven</groupId>
<artifactId>TeamSpeakBotMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</project>