我是JavaFX的新手。我用maven创建了JavaFX项目,并添加了所有依赖项。想法中的项目工作得很好,但是当我在maven中构建它并尝试在目标文件夹中打开jar时,dosn会做出反应,并且会出现以下错误。
java.lang.ClassNotFoundException:com.mysql.cj.jdbc.Driver 在java.net.URLClassLoader $ 1.run(未知来源) 在java.net.URLClassLoader $ 1.run(未知来源) at java.security.AccessController.doPrivileged(Native Method) 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.JdbcPlainTest.createConnection(JdbcPlainTest.java:21) at sample.JdbcPlainTest.ProductsSelectQuery(JdbcPlainTest.java:84) at sample.Controller.initialize(Controller.java:84) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.loadImpl(未知来源) 在javafx.fxml.FXMLLoader.load(未知来源) at sample.Main.start(Main.java:14) at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication1 $ 153 (未知来源) at com.sun.javafx.application.LauncherImpl $$ Lambda $ 51 / 881058039.run(Unkn 自己的来源) 在com.sun.javafx.application.PlatformImpl.lambda $ runAndWait $ 166(未知 资源) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 45 / 584634336.run(Unkn 自己的来源) at com.sun.javafx.application.PlatformImpl.lambda $ null $ 164(Unknown Sourc E) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 47 / 474818150.run(Unkn 自己的来源) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 165(未知S 乌尔斯河) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 46 / 501263526.run(Unkn 自己的来源) at com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 141(Unknown Source) at com.sun.glass.ui.win.WinApplication $$ Lambda $ 37 / 96639997.run(Unknown S 乌尔斯河) at java.lang.Thread.run(Unknown Source)Application start方法中的异常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(Unk nown来源) at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Sou RCE) 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)引起:java.lang.RuntimeException:Application start中的异常 方法 在com.sun.javafx.application.LauncherImpl.launchApplication1(未知所以 urce) at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication $ 147( 未知来源) at com.sun.javafx.application.LauncherImpl $$ Lambda $ 48 / 815033865.run(Unkn 自己的来源) at java.lang.Thread.run(Unknown Source)引起:javafx.fxml.LoadException: 文件:/ d:/工作%20proyeqt%20immidetely /茉莉花/ Qassa%20-%20CopyWORKING /目标/ Qassa 拷贝-1.0-SNAPSHOT.jar!/sample.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) at javafx.fxml.FXMLLoader.load(Unknown Source) at sample.Main.start(Main.java:14) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153
(未知来源) at com.sun.javafx.application.LauncherImpl $$ Lambda $ 51 / 881058039.run(Unkn 自己的来源) 在com.sun.javafx.application.PlatformImpl.lambda $ runAndWait $ 166(未知 资源) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 45 / 584634336.run(Unkn 自己的来源) at com.sun.javafx.application.PlatformImpl.lambda $ null $ 164(Unknown Sourc E) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 47 / 474818150.run(Unkn 自己的来源) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 165(未知S 乌尔斯河) at com.sun.javafx.application.PlatformImpl $$ Lambda $ 46 / 501263526.run(Unkn 自己的来源) at com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 141(Unknown Source) at com.sun.glass.ui.win.WinApplication $$ Lambda $ 37 / 96639997.run(Unknown S 乌尔斯河) ... 1更多引起:java.lang.NullPointerException at sample.JdbcPlainTest.ProductsSelectQuery(JdbcPlainTest.java:108) at sample.Controller.initialize(Controller.java:84) ... 23更多异常运行应用程序示例。主要
答案 0 :(得分:1)
似乎您的依赖项未包含在jar中。打开.jar并查看是否所有依赖类(如com.mysql.cj.jdbc.Driver)都在里面。如果不是,请参阅Including dependencies in a jar with Maven。