nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Seeking clarification behind the error message: JavaFX runtime components are missing... #385

Closed c-wenlong closed 8 months ago

c-wenlong commented 8 months ago

Problem

As I am a Mac user with M1 core, my .jar file runs fine on my friend's MacBook (M1) but not my other friends MacBook (Intel), and it doesn't run on 4/4 of my friends' Windows (Intel).

How I fixed it.

Following #241 , I moved my Launcher.java from src/java/kbot/gui to src/java/kbot as shown below after the change. Furthermore, I renamed my original file containing the start() method for the Application from KBot.java to Main.java.

Screenshot 2024-02-23 at 14 39 18

Question

So, at this moment, since I made the changes in a single commit, I do not understand what exactly made my jar file work. And I am seeking to clarify why my original program works for M1 Mac users but not for Intel users whereas the fix made it work on all devices.

aureliony commented 8 months ago

Refer to https://github.com/javafxports/openjdk-jfx/issues/236#issuecomment-426583174

c-wenlong commented 8 months ago

Refer to javafxports/openjdk-jfx#236 (comment)

Sorry, Im not exactly sure how the discussion here answers my concern about the error.

The reason is that the Java 11 runtime will check if the main class extends javafx.application.Application, and if that is the case, it strongly requires the javafx platform to be available as a module, and not as a jar for example.

What I gather from this is that the JavaFX module has to be present within the user's computer and that the main class has to extend Application, which were steps I took. Maybe you can help me draw the link here? Appreciate the help!

E0735389 commented 8 months ago

looks somewhat similar to my question #369 (the provided comment just say "some classpath issue" with no explanation)

aureliony commented 8 months ago

It was discussed here: http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/021977.html

Quote from the java.net link:

This error comes from sun.launcher.LauncherHelper in the java.base module. The reason for this is that the Main app extends Application and has a main method. If that is the case, the LauncherHelper will check for the javafx.graphics module to be present as a named module:

Optional om = ModuleLayer.boot().findModule(JAVAFX_GRAPHICS_MODULE_NAME);

If that module is not present, the launch is aborted. Hence, having the JavaFX libraries as jars on the classpath is not allowed in this case.

In other words, it's the behaviour of sun.launcher.LauncherHelper itself. If you're interested you can read the source code here: https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/sun/launcher/LauncherHelper.java

c-wenlong commented 8 months ago

Got it, I will just take it as a classpath specification that requires Launcher.java to be in the same directory as the other packages. Thanks!