Java 编译到Jar后找不到Derby EmbeddedDriver类

Java 编译到Jar后找不到Derby EmbeddedDriver类,java,jdbc,intellij-idea,jar,derby,Java,Jdbc,Intellij Idea,Jar,Derby,我正在使用Derby嵌入式驱动程序创建一个可执行jar。当从IDE启动时,应用程序按预期运行(我使用IntelliJ)。错误是在创建jar之后收到的,因此我认为问题在于依赖项没有被编译到jar中 但是,derby.jar文件显示在外部库下。我还尝试手动添加…\java\jdk1.8.0_131\db\lib作为依赖项,但没有成功 编辑:此项目是一个JavaFX应用程序,由IntelliJ预设的JavaFX应用程序项目类型生成。在添加了db\lib依赖项之后,我设置了项目结构>项目设置>工件来生

我正在使用Derby嵌入式驱动程序创建一个可执行jar。当从IDE启动时,应用程序按预期运行(我使用IntelliJ)。错误是在创建jar之后收到的,因此我认为问题在于依赖项没有被编译到jar中

但是,derby.jar文件显示在外部库下。我还尝试手动添加…\java\jdk1.8.0_131\db\lib作为依赖项,但没有成功


编辑:此项目是一个JavaFX应用程序,由IntelliJ预设的JavaFX应用程序项目类型生成。在添加了db\lib依赖项之后,我设置了项目结构>项目设置>工件来生成一个JAR(我还使用了generate Java FX应用程序,结果没有任何差异)。我还添加了META-INF/MANIFEST.MF


我的问题是,我做错了什么,或者错过了什么


代码:

错误:

C:\Users\<Username>\IdeaProjects\HelloWorld\out\artifacts\HelloWorld_jar>java -jar HelloWorld.jar
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherIml.java:389)
    at sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    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)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at sample.Main.start(Main.java:20)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more
Exception running application sample.Main

以下是其他类似问题的列表,但是,这些问题都没有帮助:

  • 关于驾驶员的其他问题:
  • 关于构建罐子的其他问题
  • 我还从tutorialspoint查看了嵌入式JDBC应用程序的教程:

  • 这是什么类型的项目?你是怎么编译的?Jar中的
    META-INF/MANIFEST.MF
    的内容是什么。请注意,在编译Java的正常方式中,外部依赖项不包括在已编译的jar中,它们是从清单中引用的(这取决于您的项目的管理/编译方式,您可能需要自己完成)。@MarkRotteveel在编辑中回答了您的问题。我明白我想要包含jar是不正常的,事实上,这是没有必要的,因为jar附带了JRE。尽管如此,我仍然不明白为什么它找不到驱动程序,因为无论编译中是否包含jar,JVM都应该能够在JRE中找到所需的jar。这是什么类型的项目?你是怎么编译的?Jar中的
    META-INF/MANIFEST.MF
    的内容是什么。请注意,在编译Java的正常方式中,外部依赖项不包括在已编译的jar中,它们是从清单中引用的(这取决于您的项目的管理/编译方式,您可能需要自己完成)。@MarkRotteveel在编辑中回答了您的问题。我明白我想要包含jar是不正常的,事实上,这是没有必要的,因为jar附带了JRE。尽管如此,我仍然不明白为什么它找不到驱动程序,因为无论编译中是否包含jar,JVM都应该能够在JRE中找到所需的jar。
    C:\Users\<Username>\IdeaProjects\HelloWorld\out\artifacts\HelloWorld_jar>java -jar HelloWorld.jar
    Exception in Application start method
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherIml.java:389)
        at sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
        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)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at sample.Main.start(Main.java:20)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
        ... 1 more
    Exception running application sample.Main
    
    Manifest-Version: 1.0
    Main-Class: sample.Main