I am trying to load my *.fxml files, which are located in a differnt package, packed in a JAR.
My folder structure: (all folders are in the classpath)
- src/main/java:
- com.test.controller
- Application.java
- com.test.view
- Main.fxml
- src/main/test: contains unit tests
- src/main/resources: contains images
As mentioned here I use the following statement to load the FXML file. (without the leading slash "/") The method is called in the Application.java
file.
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("com/test/Main.fxml")
This works quite fine if I run the project within eclipse, but fails with a java.lang.IllegalStateException: Location is not set
if I execute the JAR (which was created with Gradle)
If I unpack the JAR file, I can see the Main.fxml
under /com/test/
, so the file does exist.
I tried several variations of accessing the FXML file in a different package, but nothing worked. Does somebody know what to do here?
I would rather not move the FXML File to the resource folder (like stated here, because I assume it should be either possible to access the files where they are now.