I'm trying to style a JavaFX WebEngine using the setUserStyleSheetLocation method. The method's documentation says it requires a "local URL" starting with data:
, file:
, jar:
, or jrt:
. I want to package my project in a runnable JAR file, but I don't know where to put my web.css
file nor what to pass into the setUserStyleSheetLocation
method in order for my app to detect the CSS file at runtime.
My project structure is:
- OuterProjectFolder
- src
- pack
- Main.java
- resources
- web.css
but I can move web.css
if needed.
Given the above placement of web.css
, I have tried passing all of the following literal strings to setUserStyleSheetLocation
, to no avail:
file:web.css
jar:web.css
file:resources/web.css
jar:resources/web.css
file:/resources/web.css
jar:/resources/web.css
file:src/resources/web.css
jar:src/resources/web.css
and I have also tried passing:
Main.class.getResource("/resources/web.css").toString()
Main.class.getResource("/resources/web.css").toExternalForm()
To create my JAR, I am using Eclipse's File > Export... > Runnable JAR File
with "Library handling" set to "Package required libraries into generated JAR." I have double-checked that the CSS file is actually in my JAR. My app is able to load other things from my resources
folder such as images and even other CSS files (like the one used to style my Scene
).
Any help would be sincerely appreciated.