As long as I run my project directly from Eclipse, I have no problem with that:
scene.getStylesheets().add(getClass().getResource("/stylesheet.css").toExternalForm());
But as soon as I run this code inside of a jar file, the resource is not found (NullPointerException
).
I tried moving the css
file to my src
folder and then only stylesheet.css
as path instead of /stylesheet.css
, but this leads to the same problem: Works fine using Eclipse, but not from the jar.
Hint: I am using Zonskis Maven JavaFX Plugin for generating the jar.
I just wasted my (your) time writing silly maven profiles.
instead of :
scene.getStylesheets().add(getClass().getResource("/stylesheet.css").toExternalForm());
scene.getStylesheets().add("stylesheet.css");
This is how Zonski load css
files.
Of course your stylesheet.css
file should be in /src/main/resources
, or somewhere on the CLASSPATH
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With