last day (15 days later) » 

7:52 PM
0
Q: Css is not working after deployment of a JavaFX app in Eclipse

user3435407If I deploy a JavaFX app from Eclipse then it won't load the CSS file for some reason, though the app works as expected inside Eclipse. Main class: public class Main extends Application { Stage primaryStage; @Override public void start(Stage primaryStage) { this.primaryStage = primaryS...

 
Can you tell me where exactly is your .class and .css file present inside build/classes directory?
 
hi, they are in: workspace/JavaFXTester6_Web/build/build/classes/application - here is the .class the .fxml and the .css JavaFXTester6_Web is the projects name.
 
If all the three files are located in the same package, it should get loaded. Can you add a snapshot of the directory structure? (I know, adding a "/path-to-your-css" will solve your issue, but I am just curious about the structure.)
 
they are really in one folder, please see the edited post
 
To make it work use Main.class.getResource("/application/style.css").
Btw, why do you have build directory twice?
 
7:52 PM
Nope, it doesn't want to do it, unfortunately it is still not applying the CSS outside of Eclipse. I don't know why is the build folder duplicated. It is generated so by the build.fxbuild when I press build and run. If I just press build, then I get the build folder with the build.xml in it. When I run it then it creates the sub folders as you see again. So there is no difference between build & build and run. Every setting is default, I only fill in the obligatory fields marked with *s.
Now I tried to copy the content of the second build folder to its parent folder and then delete the second build folder, but with no success.
 
This is strange, I tried your build.xml on one of my projects and things work fine
 
Hi, thank you for taking your time to help me!
 
so, my last comment was, that the duplicate is solved, I thought that I should set the build folder to build folder, now the build folder is the project, now it doesn't generate a double build folder
 
build folder should be generated on its own
 
7:56 PM
But it is still not loading / applying the CSS
so I recreate everything step by step, now I delete the build folder
 
delete the build and dist
then run the build.xml
 
ok i try
still no css
 
lets do it step by step
 
I get the same file tree as you, the app opens up from the jar file, but the button is still not blue.
ok
 
what css are you using ?
for coloring the button?
 
8:02 PM
yes
@CHARSET "UTF-8";

.button{
-fx-background-color: blue;
}
 
ok, that should work
 
this is in the style.css
 
how are you loading the css?
 
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Mainwindow.fxml"));
AnchorPane ap = loader.load();
ap.getStylesheets().add(Main.class.getResource("/application/style.css").toExternalForm());
in Eclipse the app starts and the button is blue
 
ok..
Is the css present in build/classes?
 
8:04 PM
yes, under the application folder
 
great, so far we are good
 
so build/application and there are the 3 files
 
build
    |
   classes
        |
       application
              |
              java/css/fxml
 
yep
 
this should be the directory structure
so great we are making progress ;)
 
8:06 PM
im full of hope :)
 
Now I would like you to un-archive the jar present inside the deploy directory present parallel to build dir
 
wait a sec
you mean there should be the java file or the byte code?
so did you mean class/css/fxml ?
 
My bad, I stand corrected :D
 
ok
I have the jar/html/jnlp under deploy folder
 
8:10 PM
if I open the jar with archive manager
 
you must have two directories application and META-INF
Inside application you must have all 3 files
 
i have application ans META-INF, in the META-INF : MANIFEST.MF, SIGNATURE.BSF
yes, all good
 
great
 
there are the 3 files
 
so how are you trying to run the jar?
 
8:12 PM
duobleclick
 
lets take the terminal way
 
so that we make check the exceptions (if any)
Do you know how to do that?
browse into the deploy directory by typing -- cd /home/zooey/LinuxEclipse/linuxWorkspace/JavaFXTester6_Web/deploy
 
Apr 11, 2015 10:15:36 PM com.sun.javafx.css.parser.CSSParser parse
WARNING: CSS Error parsing jar:file:/home/zooey/LinuxEclipse/linuxWorkspace/JavaFXTester6_Web/deploy/JavaFXTester6_Web.jar!/application/style.css: Expected LBRACE at [1,9]
 
then fire the command java -jar JavaFXTester6_Web.jar
 
8:17 PM
we have something
 
great
its a parsing error
ahhh
now I got it
 
cool man :)
 
you need to remove @CHARSET "UTF-8"; from your css
remove everything but
.button{
       -fx-background-color: blue;
}
 
checking...
you are great mate! im really glad, thank you!
i was searching for this since 2 days
i really like javafx but it is a bit like a jungle fight sometimes :)
if edit the question, so that there is the problem, and then you can answer it, i can vote it up
 
you never posted the correct css in the question, so it took sometime.
 
8:23 PM
yes, my fault, im sorry, I didn't expected that one to be important
 
But nevermind, we found the bug and smashed it :D
 
are like a developer?
(I don't want to misuse you time, just asking)
 
yes I am
 
I hope you get paid for this :)
as long we can't send beer digitally :)
 
Paid for what?
 
8:24 PM
for the help
 
haha
people don't get paid for helping people on SO
and I don't work for SO :D
 
well then, when I will be expert some day i give it back...
thank you very much! I edit the question, so you can answer it
 
I am just killing my free time in here :)
 
:)
I edited it. Thank you again and all the best!
 

last day (15 days later) »