5

Starting with badass-runtime-example-javafx which works for me, I copied this project and extended it with my own code. I created an image with gradlew runtime. When executing the generated .bat file on Windows, I get "Error: JavaFX runtime components are missing, and are required to run this application".

In build.gradle, I added an additional module javafx.fxml:

javafx {
    modules = ['javafx.controls', 'javafx.fxml' ]
}

I also ran the suggestModules task and added the suggested modules to

runtime {
    modules = ['java.naming', 'java.xml ...']
}

My question is how I can analyze which modules are missing from the Java runtime. I see that java.exe is executed only with -classpath (which includes the application jar) and the main class parameter.

Is java --list-modules the answer? I see there is a large file "modules" in build\image\lib which looks important to me.

I am looking for an analytical method of discovery to solve the problem.

user250343
  • 1,163
  • 1
  • 15
  • 24
  • 6
    If the JavaFX library is on the class-path then your main class _cannot_ be an instance of `Application`. You'll have to create a separate launcher class an invoke `Application.launch(YourApp.class, args)` from the main method. If that doesn't help, please provide a [mre] demonstrating the problem. – Slaw Apr 27 '20 at 01:58
  • If I had a minimal reproducible test case then that would expose the solution. It's the complexity that is the problem. The sample app provided works without a separate launcher class. I did not change the architecture so the error must be somewhere else. As per problem statement, I need an analytical method. I know how to get out of this which is to incrementally roll forward from the example to what I have. But I can no longer accept this approach because the problem could happen again with complexity increasing. I need a method that lets me explore the environment to find what is missing. – user250343 Apr 27 '20 at 02:48
  • The sample you linked to has a separate launcher class, it just calls `HelloFX.main(args)` instead of `Application.launch(...)` directly. – Slaw Apr 27 '20 at 02:50
  • 1
    The error you mention is typically caused by having the `javafx.graphics` module on the classpath but the main class is a subclass of `Application`. It's due to an implementation detail deep within internal code and is fixed by having a separate launcher class. I'm not sure an error with that exact wording can occur for any other reason. – Slaw Apr 27 '20 at 02:55
  • Thanks Slaw, I would accept your answer as the solution - Creating a launcher class as the external main class calls the Application main method, as in the example. Meanwhile, I am puzzled by `java.lang.NoClassDefFoundError: javax/script/Bindings` when using `com.airhacks:afterburner.fx.1.7.0` - only from the generated runtime, not in the IDE. I may need to open another question for that. – user250343 Apr 27 '20 at 15:36
  • @Slaw can you kindly demonstrate how to add the separate launcher class? Use this snippet to demonstrate https://gist.github.com/RyanKoech/15e2dd446f5424c2fe86249e5528289d . – Kochez Jan 30 '22 at 11:13
  • @Kochez Added example in comment to your gist – Slaw Jan 30 '22 at 21:08

0 Answers0