How to convert css into bss

天涯浪子 提交于 2019-12-18 06:57:19

问题


I found this post http://docs.oracle.com/javafx/2/deployment/packaging.htm#BABCACBD

Can you tell me how I can use this tool to convert css files into bss files? From the information on the web site it's not very clear how I can use it for JavaFX application.

Any help will be highly appreciated.


回答1:


Let's imagine your jdk 8 home bin directory is on your shell path.

Create Love.java:

import javafx.stage.*;
import javafx.application.*;
import javafx.scene.control.*;
import javafx.scene.*;

public class Love extends Application {
  public void start(Stage stage) throws Exception {
    Scene scene = new Scene(new Label("hello, world"));
    scene.getStylesheets().add("love.css");
    stage.setScene(scene);
    stage.show();
  }
}

Compile it:

javac Love.java

Create love.css:

.label { -fx-text-fill: firebrick; }

Compile it:

javafxpackager -createbss -srcfiles love.css -outdir . -outfile love

This will create love.bss

Now you can delete love.css as you don't need it anymore as you have made binary love.

Now run your app:

java Love

Even though you requested love.css, the JavaFX runtime was smart enough to recognize that you have a binary love.bss and use that to apply css styles to your app.




回答2:


On Windows, I like to do this through a batch file (note that you need to have JAVA_HOME system variable defined). You can create a new .bat file, copy the code below and save it. You can then run this batch file from the same folder where your .css files are stored:

@echo off

for %%f in (*.css) do (
    "%JAVA_HOME%\bin\javafxpackager" -createbss -srcfiles "%cd%\%%f" -outdir . -outfile %%~nf
)

echo.
echo Press any key to exit . . .
pause>nul

Basically jewelsea perfectly explained the solution, just note that it will work only if your css file has some content in it. For example, it will not work on empty application.css which gets created by e(fx)clipse, so you can simply put something like .dummy-class {-fx-background-color: red;} inside and then convert it.



来源:https://stackoverflow.com/questions/20068627/how-to-convert-css-into-bss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!