0

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.

Community
  • 1
  • 1
Kristianasp
  • 61
  • 11

1 Answers1

0

You don't say what was done to setup your project in IntelliJ so I assume you added the Jar at some point.

You need to add the SQLite JDBC driver to your classpath. It is found when running inside of your IDE but not from the command line.

You can get more information here: Java: how to import a jar file from command line and http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

Community
  • 1
  • 1
Ken Brittain
  • 2,255
  • 17
  • 21
  • Essentially, his JDBC driver is a dependency and he needs to include it in the JAR (or include a dependency manager that will handle it for him) – Harmelodic Mar 17 '16 at 01:01
  • It is possible to that I'll have to do that, but thats sort of the "next problem" as this is happening just because it can't find the path specified. I'm having the same problem when the program is supposed to load the FXML file. – Kristianasp Mar 17 '16 at 06:40