Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scene.getStylesheets().add() not working inside jar file

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.cssas 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.

like image 797
stefan.at.wpf Avatar asked Apr 29 '13 19:04

stefan.at.wpf


1 Answers

I just wasted my (your) time writing silly maven profiles.

instead of :

scene.getStylesheets().add(getClass().getResource("/stylesheet.css").toExternalForm());

simply write :

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.

like image 136
Salah Eddine Taouririt Avatar answered Sep 28 '22 14:09

Salah Eddine Taouririt