1

I've created binary stylesheets from my css files (located in module/src/main/resources/styles) using

javapackager -createbss -srcdir . -outdir .

As per this answer and the recommendation in this report I load them with

scene.getStylesheets().add("styles/style.css");

and removed the .css files just to test that JavaFX does indeed look for existing .bss files even if they're referenced as .css.

Running the application, however, gives the following error:

Feb 03, 2017 3:42:47 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged WARNING: Resource "styles/style.css" not found.

Inspecting loadStylesheetUnPrivileged() I can see that it can indeed find the files in the resources folder and starts reading them, but fails in DataInputStream.readUTF() with an EOFException. Then, as expected, it tries to find the .css files I deleted and gives the message above when that obviously fails.

I'm working on Java 8u40, but have tried 8u112 also with the same behaviour.

Is there anything I should look for in my .css files that may be causing the generated .bss to be invalid? I could not find any documentation on limitations of this technology.

I'd be happy to provide any missing info.

UPDATE

I've reduced the .css to the minimum, and still the corresponding .bss is failing to be read. This rules out unsupported keywords as an issue. For reference, here is the minimised .css:

.button {
    -fx-background-color: blue;
}

On the other hand, I created a small test application (very similar to the one in the answer mentioned above) loading the same minimal .css converted to .bss, and it works as expected. Same version of Java used in both (8u40), same javapackager too. The test app:

public class Main extends Application {
    @Override
    public void start(Stage stage) throws IOException {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("/Mainwindow.fxml"));
            AnchorPane ap = loader.load();
            ap.getStylesheets().add("styles/style.css");

            Scene scene = new Scene(ap);
            stage.setScene(scene);
            stage.show();
    }
}

The generated binary files are also identical, as expected: link to image here, not enough rep to embed :)

I'm not sure what in the environment could be causing the main application to fail to load the exact same .bss?

Community
  • 1
  • 1
fax
  • 11
  • 1
  • 4
  • As described, `loadStylesheetUnPrivileged()` looks for a corresponding .bss file even if the request is for the .css . Tracing it with a debugger shows it correctly finding the .bss and only defaulting to the .css when that fails. [deleted comment asked if I shouldn't be referencing style.bss] – fax Feb 03 '17 at 16:06

1 Answers1

0

It was indeed a difference in the environment: the .bss files were being filtered by maven when the resources plugin was copying them from the source directory into the jar or classes folder while building. This was essentially corrupting the files.

So the solution was to add an exclude clause to the project's pom.xml:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
          ...
          <exclude>**/*.bss</exclude>
        ...
fax
  • 11
  • 1
  • 4