Can not work with MediaPlayer class, javafx.media is not found

Note: This answer applies to other JavaFX modules such as fxml and web, as well.


javafx.media is a module, you need to require it in your module-info.java like you do for javafx.controls and javafx.fxml.

module org.project {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.media;

    opens org.project to javafx.fxml;
    exports org.project;
}

There may be other issues, but that is a likely one.


I don’t recommend using the 11.0.0-ea1 release, there are later more stable versions. Latest stable release of JavaFX is 15 https://mvnrepository.com/artifact/org.openjfx/javafx-media/15, so I would advise you use that for all of your JavaFX dependencies.

<!-- https://mvnrepository.com/artifact/org.openjfx/javafx.media -->
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-media</artifactId>
    <version>15</version>
    <type>pom</type>
</dependency>

For later readers referring to this post, please use the most up to date non-early access release you can find using mvnrepository or a similar search tool.

tried to download the library jar but it is empty

Don’t do this for JavaFX dependencies. JavaFX needs to include both native libraries and Java libraries. Just downloading Jar files may not work for you as you may be missing required stuff. Plus there may be transitive imports for libraries required which, again, just downloading a single jar won’t pick up. You are already using a dependency hierarchy build tool in Maven, just configure and use it correctly and let it do its job.

Additionally, I think the javafx.media artifact was incorrectly named, configured and uploaded to maven central, which is why it only existed there as a 11.0.0-ea1 version. It should have been named javafx-media, which it is on subsequent uploads, so use the correct name for the artifact and then the most recent versions are there which include all the correct artifact data in the maven central repository.

My pom.xml dependencies

Your pom.xml dependencies mix JavaFX versions for different JavaFX dependencies. Don’t do this, the different versions won’t be compatible. Use the same version for all JavaFX dependencies.

i went to file> project structure > libraries > add library “java”, opened the path where i installed my javafx > lib and chose javafx.media, then module-info.java could recognize it.

You should have your IDE re-import the updated maven project and auto-resolve the dependencies, not add the libraries manually to the IDE project.

For Idea, see:

For other IDEs the procedure will differ.


If you want to use WebView, or FXML or Controls, then use the sample module and dependency names here.

All steps for usage of these modules are the same as for the javafx.media module, only the names change.

Sample module names:

javafx.web
javafx.swing
javafx.fxml
javafx.media
javafx.controls

Sample dependency artifact names:

javafx-web
javafx-swing
javafx-fxml
javafx-media
javafx-controls

Leave a Comment