Home >Java >javaTutorial >How to Resolve JavaFX Media Module Errors When Running a JavaFX 11 Application?
Problem:
When running a JavaFX 11 application with the command provided in the question, an error is encountered related to illegal access between classes in the javafx.media and javafx.graphics modules.
To resolve the error and run the application successfully, ensure that the javafx.media module is resolved as a named module during application launch. This can be accomplished through one of the following methods:
1. Include the Module in the --add-modules Argument:
Modify the command to include javafx.media as an additional module in the --add-modules argument:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java -p ~/.m2/repository/org/openjfx/javafx-swing/11/javafx-swing-11.jar: ~/.m2/repository/org/openjfx/javafx-swing/11/javafx-swing-11-linux.jar: ~/.m2/repository/org/openjfx/javafx-graphics/11/javafx-graphics-11.jar: ~/.m2/repository/org/openjfx/javafx-graphics/11/javafx-graphics-11-linux.jar: ~/.m2/repository/org/openjfx/javafx-base/11/javafx-base-11.jar: ~/.m2/repository/org/openjfx/javafx-base/11/javafx-base-11-linux.jar: ~/.m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11.jar: ~/.m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-linux.jar: ~/.m2/repository/org/openjfx/javafx-media/11/javafx-media-11.jar: ~/.m2/repository/org/openjfx/javafx-media/11/javafx-media-11-linux.jar --add-modules javafx.controls,**javafx.media** -classpath ...
2. Make Your Own Code Modular:
Create a module-info.java file in your project directory with the following content:
module my.application { requires javafx.controls; requires javafx.media; // Replace with your Application class' package exports com.example.myapp to javafx.graphics; }
Then, launch your application with the --module argument to specify your custom module:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java --module my.application --add-modules javafx.base,javafx.graphics,javafx.controls -classpath ...
3. Use a JDK that Includes JavaFX:
Download a JDK that includes JavaFX, such as BellSoft Liberica or Azul Zulu, and use that to run your application.
Additional Notes:
The above is the detailed content of How to Resolve JavaFX Media Module Errors When Running a JavaFX 11 Application?. For more information, please follow other related articles on the PHP Chinese website!