0

I have a GluonFX Maven Java17 Linux application that works fine when I run gluonfx:run and gluonfx:runagent. However, when I build it using gluonfx:build and then run the standalone app I am missing CSS settings, menu item labels, etc.

The menu items are interesting because they are there but don't have any name labels. It's the same with right-click context menus in that they appear but with no labels.

Maybe the menu item labels are also being affected by failing to load CSS content.

What is the runtime difference between gluonfx:run and running the app that would make this happen?

Has anyone else seen this?

Firstly, the standard Maven structure of src/main/java, src/main/test is not adhered to but instead src/apppackages, test/apppackages. Then inside Maven we have the following to point to the correct locations:

<build>
...
<sourceDirectory>${project.basedir}/src</sourceDirectory
<testSourceDirectory>${project.basedir}/test</testSourceDirectory>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
...

The CSS files are typically loaded within the .fxml files; eg:

...
<stylesheets>
    <URL value="@classfilename.css" />
</stylesheets>

Inside class the CSS files are typiclly loaded as follows:

URL urlCSS = getClass().getResource("classcssfile.css");

and fxml files loaded as follows:

URL url = getClass().getResource("About.fxml");

Like to add that built a second version of the software using the standard Java src/resources structure and got the same issue in not correctly rendering controls.

GluonFX/GraalVM version: graalvm-svm-java17-linux-gluon-22.1.0.1-Final

*** Steps To Reproduce ***

  1. Go to [https://start.gluon.io/] and generate the minimal app by unchecking everything so that the code looks like that below.

  2. run mvn gluonfx:run, followed by mvn gluonfx:runagent. In both cases you will see the Label in blue.

  3. Now run mvn gluonfx:build. Double-clicking the resulting app you will not see the blue Label.

  4. The "com/mycompany/sample/styles.css" entry is there in META-INF/resource-config.json

  5. When run in Terminal, we get a warning related to the un-named module:

./My\ Gluon\ Application Jul 23, 2023 2:01:40 PM com.sun.javafx.application.PlatformImpl startup WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @71c7db30'

package com.mycompany.sample;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");

        ImageView imageView = new ImageView(new Image(Main.class.getResourceAsStream("openduke.png")));
        imageView.setFitHeight(200);
        imageView.setPreserveRatio(true);

        VBox root = new VBox(30, imageView, label);
        root.setAlignment(Pos.CENTER);

        Scene scene = new Scene(root, 640, 480);
        scene.getStylesheets().add(Main.class.getResource("styles.css").toExternalForm());
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Graham Seed
  • 742
  • 3
  • 10
  • 24
  • Can you post how you load the css file? Also include GraalVM and GluonFX plugin versions. – José Pereda Jul 18 '23 at 10:50
  • Thanks for your reply - I've added some additional info to the original post. I also tried adding [${project.basedir}/resources/resourceconfig.json] to the Maven plugin and listing a few of the CSS and FXML files, but it made no difference. – Graham Seed Jul 18 '23 at 12:49
  • When you run `gluonfx:runagent`, check that the `${project.basedir}/src/resources/META-INF/native-image/` folder and the config files are created. Then see that those are found when you run `gluonfx:build`(see the logs, check the command line for `native-image` and make sure all paths are correct). – José Pereda Jul 18 '23 at 15:16
  • The folder is created and the config files are created. But I don't see any app resources listed in resource-config.json. When I run the sample created by [https://start.gluon.io/] I see that it adds entries such as ["pattern":"\\Qcom/mycompany/sample/styles.css\\E"]. I've tried adding a entry to the pom.xml but it's not having any affect. – Graham Seed Jul 18 '23 at 17:11
  • The goal `gluonfx:runagent` is a "wrapper" around the GraalVM native agent. See [code](https://github.com/gluonhq/gluonfx-maven-plugin/blob/master/src/main/java/com/gluonhq/NativeRunAgentMojo.java). Since you are running outside the expected `src/main/java|resources` folders, it is possible that it fails at some step. Based on the log of that goal, you could try to run the native agent yourself, and see that the correct config files are generated. – José Pereda Jul 18 '23 at 17:20
  • Thanks again. I see from the log that the files are being copied, just that there's nothing in them apart from default settings. An example of them being coped to /tmp [Copied resource .../target/classes/META-INF/native-image/resource-config.json to /tmp/classes16948668735808230786/META-INF/native-image/resource-config.json] – Graham Seed Jul 18 '23 at 17:25
  • I reworked the application to use the standard Java/Maven build structure of sr/main/java|resources and still get the same issue of non-visible labels on menu items. I removed all calls to setting .css and still have the same issue. There is something weird going on that I simply do not understand. – Graham Seed Jul 19 '23 at 18:02
  • Interesting, that shouldn't happen. Have you tried adding a Menu and some MenuItems to the sample from start.gluon.io? – José Pereda Jul 19 '23 at 18:06
  • No - I have run this neat sample generator before and got things to work but will try again. What puzzles me is how I see all of the JavaFX controls in runagent mode but not in native-image mode. – Graham Seed Jul 20 '23 at 08:33
  • Those are quite different things: runagent runs on the JVM (it is just the same as `mvn javafx:run`), while `mvn gluonfx:nativerun` runs a binary executable that results from the build process with native-image. The GluonFX does many things under the hood in that process, but still, something could go wrong... – José Pereda Jul 20 '23 at 11:00
  • Added a "Steps To Reproduce" in the original post. BTW - "mvn gluonfx:nativerun" fails with the Java17 build and yet I thought Java17 had LTS. – Graham Seed Jul 23 '23 at 13:04
  • Is this issue only on Linux? I don’t understand what you mean with executable failing and LTS. – José Pereda Jul 23 '23 at 14:03
  • Now "mvn gluonfx:nativerun" is working. Previously it was throwing an exception. However, I still get the un-named warning as posted above. I've been trying to resolve the issue I have for a week and I have found inconsistent behaviour from time to time. I suppose it is doing a lot but it doesn't instil me with confidence. I hope you or others can reproduce the above steps. I could take a screenshot but I simply don't see the Label. I thought it was old Java8 css but looks like it is something else. – Graham Seed Jul 23 '23 at 15:33

0 Answers0