I have a project I'm trying to export to a JAR file. Building the JAR itself works fine and it seems like all the necessary files are being included into the JAR. The problem I have is when I have code like this in one of my classes:
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:player/resources/test.db");
It is also not working for this code:
FXMLLoader load = new FXMLLoader(getClass().getResource("commonGUI.fxml"));
Running the project through IntelliJ works fine but when building and running the JAR file, I get this exception:
java.sql.SQLException: path to 'player/resources/test.db': '/Users/Kristian/Documents/Uni/Freelance/SEProjects/SE18/working/Plookify/out/artifacts/Plookify_jar/player' does not exist
or this depending on which file I'm trying to load:
Caused by: javafx.fxml.LoadException:
file:/Users/Kristian/Documents/Uni/Freelance/SEProjects/SE18/working/Plookify/out/artifacts/Plookify_jar/Plookify.jar!/common/commonGUI.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at common.openMainGUI.start(openMainGUI.java:21)
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)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at common.commonGUIController.loadPlayerPane(commonGUIController.java:43)
at common.commonGUIController.initialize(commonGUIController.java:31)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 14 more
How to solve an issue like this?
Solved
Problem has been solved. To solve the SQLException, the DB file had to be placed outside the JAR file. For the FXML error, the paths in the project code had to be modified.