By default Maven checks for the resources folder based on Standard Directory Layout . Though there is a problem with the final jar.
It finally adds all the resources outside the src/main folder which is making my JavaFX application crass .
Caused by: java.lang.NullPointerException: Input stream must not be null
at javafx.graphics/javafx.scene.image.Image.validateInputStream(Unknown Source)
at javafx.graphics/javafx.scene.image.Image.<init>(Unknown Source)
at main.java.com.goxr3plus.xr3player.application.tools.InfoTool.getImageFromResourcesFolder(InfoTool.java:734)
at main.java.com.goxr3plus.xr3player.application.Main.start(Main.java:324)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
... 1 more
Because i am loading the images from the src/main/resources folder like :
class.getResourceAsStream("/main/resources/image/"+ imageName));
And in the final jar the images folder is not under the main folder . I used to have resources folder outside src
folder and everything seemed okay , though i wanted to follow Standard Directory Layout so i moved it . Before everything worked well using :
class.getResourceAsStream("/image/"+ imageName));
This is currently directory layout :
What you suggest ? Should i load the images differently? ....
Only that code works now class.getResourceAsStream("/main/resources/image/"+ imageName));
Can somehow tell Maven how to package the resources folder on the final jar ?
After many restarts and clean project and Maven Update Project ... it seems it was Eclipse related problem ... never mind i will leave this question here as it may be useful to someone in the future :)
Your jar file looks like the expected standard layout.
If you have src/main/resources/image/imageName.png
, it would show up in /image/imageName.png
in the jar file (in your screen shot, you do have that directory, so that looks good).
You can load it with class.getResourceAsStream("/image/imageName.png")
.