so im using javafx in a mixed java/kotlin project,...
# tornadofx
p
so im using javafx in a mixed java/kotlin project, and im using relative paths for the images. when i use gradlew run, everything shows up as expected, but when i package it into a .jar file, the image doesnt show up. i guess the relative paths get messed up when packaging it into a .jar? im not sure how to fix that
m
Have you checked if the images is included at all in the jar file?
p
Im using gradle, and the images are placed in the resouces directory. As far as I gathered, the resources directory is included into the jar by default when building with gradle.
m
If you open the jar file with for example WinRAR can you find the image in the folder structure?
Also what java version are you using?
p
1.8
I'll try using winrar to check the jar. I didn't know you could do that, ahah.
the images are there.
m
im using
Copy code
val resource = this.javaClass.getResourceAsStream("/tray_icon.png")
when the image is in src/main/resources/tray_icon.png
but there is different ways of accessing the resource
what are you using and what is the path of the code and resource?
p
the path is in the fxml file. i was actually also having problems with loading fxml from the resources dir, so i placed the fxml files right beside the controllers in src/main/java/project (it worked that way). The path in the fxml goes from the fxml file, all the way to the root ./build dir, and then to the resources folder:
../../../../../../resources/main/image.png
i'll try it the way you are doing it
well i tried:
Copy code
URL location = getClass().getResource("resources/scenes/Welcome.fxml");
Parent root = FXMLLoader.load(location);
but it didnt work
m
i load the fxml according to this guide
Copy code
class CounterView : View() {
    override val root : BorderPane by fxml()
}
and then having CounterView.fxml in the same package
you can also checkout this project for reference https://github.com/rrva/collabster
please note that it is using java 13 and packaging jar files differently
p
i found the solution here: https://stackoverflow.com/a/19603055/13034017 Thanks a lot for the help, Max!
👍 1