Maxim Antonov
Maxim Antonov

Reputation: 305

error: package javafx.scene.media does not exist

I'm trying to create javafx media player as gradle project, but got this error.error: package javafx.scene.media does not exist on line: import javafx.scene.media.Media;

Here is my build.gradle

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'

}

group 'life.antonov'
version '1.0'

mainClassName='life.antonov.muza.Main'
sourceCompatibility = 11

jar {
    manifest {
        attributes "Main-Class": "$mainClassName"
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}
repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.openjfx', name: 'javafx-controls', version: '13'
    compile group: 'org.openjfx', name: 'javafx-fxml', version: '13 '
    compile group: 'org.openjfx', name: 'javafx-media', version: '13'


}

I'm tried to unzip downloaded javafx-media jar file and it is almost empty:

$ unzip javafx-media-13.jar 
Archive:  javafx-media-13.jar
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    

Why? Maybe I wrote wrong dependencies? What I have to do to make my application compile and work?

Upvotes: 5

Views: 10385

Answers (3)

Paul Murray
Paul Murray

Reputation: 1

Note, to use with controls, module-info should be

module com.murray {
    requires javafx.controls;
    requires javafx.media; // You must add this line
    exports com.yourApp;
}

And you need two entries in the dependency tag of pom.xml:

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>13</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>13</version>
    </dependency>
</dependencies>

Upvotes: 0

quangdang
quangdang

Reputation: 374

If you want to use MediaView control in javafx you must to do 2 steps

Step1: add requires javafx.media;

module com.codegym.videoplayerfx {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.media; // You must add this line


    opens com.codegym.videoplayerfx to javafx.fxml;
    exports com.codegym.videoplayerfx;
}

Step2: Add dependency in pom.xml for maven (or build.gradle for gradle). After that you must press build. Try orther dependency version if does't work

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>16</version>
        </dependency>

Upvotes: 2

MelvinWM
MelvinWM

Reputation: 749

I have not tested it, but:

Replace:

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

With

    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.media' ]

Upvotes: 6

Related Questions