java - 代码在导出后不起作用,但在导出之前起作用

标签 java mysql intellij-idea

我需要你的帮助。

我目前正在开发一个使用 MySQL 的 java 应用程序 (准确地说是 com.mysql.cj.jdbc.MysqlDataSource),如果我在 Intellij IDEA 中运行它,一切正常,但导出后,我收到一条错误消息:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/mysql/cj/jdbc/MysqlDataSource
        at ger.mrSoUndso.Main$1.actionPerformed(Main.java:77)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.MysqlDataSource
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 37 more

如何修复此错误?

提前致谢。

Mr_SoUndso

PS:我知道以前有人问过类似的问题,但没有堆栈跟踪。也没有给出答案。

最佳答案

一位 friend 向我展示了如何修复它:

您需要使您的库在您的 jar 中可用。 然后一切正常

关于java - 代码在导出后不起作用,但在导出之前起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43965083/

相关文章:

mysql - MySQL 下载中缺少 my-default.ini

mysql - Django 在 object.save() 上引发 MySQL 错误 1452,但 INSERT 有效

java - 在IDEA中,如何自动删除.attach_pidxxx文件

intellij-idea - 如何从 Gradle 项目中的 Kotlin 类运行 main 方法?

xml - SVG 的代码格式在 IntelliJ IDEA 中不起作用

java - 无法执行目标 org.apache.maven.plugins :maven-release-plugin:2. 5.3:prepare

Linux 和 Windows 之间的 Java 内存使用差异

MySQL 查询中的 PHP 变量从列表爆炸

java - 使用 hibernate 连接数据库时出错

java - onMapReady 并不总是被调用