4

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.

Anshul Parashar
  • 3,096
  • 4
  • 30
  • 56
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

3 Answers3

11

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.

love

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Unfortunaltly, for **java 9** the javafxpackager.exe seem to be missing. – pdem Mar 05 '18 at 14:03
  • 1
    `javafxpackager` is still in Java 9, it was renamed from `javafxpackager` to `javapackager`. – jewelsea Mar 05 '18 at 18:20
  • 1
    Not available in openjdk. It looks like [`jpackage`](https://blogs.oracle.com/jtc/a-brief-example-using-the-early-access-jpackage-utility) is the future of packaging java applications, but unfortunately only available in EA releases – smac89 Nov 20 '19 at 22:08
  • For later Java releases, e.g. 11-13, until `jpackage` is available (or if it does become available but doesn't offer css -> bss conversion), if you need to, you should be able to use the `javapackager` from an earlier release to convert the `css` to a `bss` file. – jewelsea Nov 21 '19 at 01:15
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.

Goran Vasic
  • 1,079
  • 10
  • 11
0

The commands in the other answers don't exist anymore but the code for it does.

Save the code of the Css2Bin class from JavaFX.

Then in the terminal run java Css2Bin my-styles.css. A new file named my-styles.bss will be created. (Don't forget to add all the --add-modules library stuff)

Nand
  • 568
  • 3
  • 18