Home >Java >javaTutorial >How to Resolve JavaFX Media Module Conflicts and IllegalAccessError?

How to Resolve JavaFX Media Module Conflicts and IllegalAccessError?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-20 16:29:11732browse

How to Resolve JavaFX Media Module Conflicts and IllegalAccessError?

JavaFX Media Application Module Error

Question:

When running a JavaFX 11 application, an error occurs due to a module conflict:

java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x4d7be377) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x4d7be377

Answer:

The error suggests that the JavaFX media module is not being resolved properly as a module, resulting in the conflict. To resolve this, ensure that the javafx.media module is included in the module path.

Three Ways to Resolve the Module Conflict:

1. Include javafx.media in --add-modules:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java \
-p ~/.m2/repository/org/openjfx/javafx-swing/11/javafx-swing-11.jar: \
... \
-classpath ~/development/intellij/OpenPatrician/OpenPatricianStandalone/target/classes: \
... \
--add-modules javafx.controls,javafx.media

2. Make your code modular and add requires javafx.media; to your module descriptor.

3. Use a JDK that includes JavaFX (e.g., BellSoft Liberica or Azul Zulu).

Additional Notes:

  • Ensure the JavaFX modules are not also included on the classpath.
  • If using Maven, include the javafx.media module as a dependency in your pom.xml.

The above is the detailed content of How to Resolve JavaFX Media Module Conflicts and IllegalAccessError?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn