为什么 Javafx 本机映像不能与 class javafx.scene.media.MediaPlayer 一起使用?

Why does Javafx native image does not work with the class javafx.scene.media.MediaPlayer?

我使用 gluon 插件和 graalvm ce 21.0.0 在 win 10 上构建本机映像。如果我在没有 javafx.scene.media.MediaPlayer 的情况下构建应用程序,则客户端可以正常工作。如果我使用 class javafx.scene.media.MediaPlayer 我意识到文件夹 \target\client\x86_64-windows\gvm\tmp\deps 不包含 javafx-media 的 jar。但为什么?以及如何解决?当我 运行 客户端时,出现以下错误:

[Di. März 30 20:50:58 MESZ 2021][INFO] ==================== RUN TASK ====================
[Di. März 30 20:50:58 MESZ 2021][FINE] Start process run until end...
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB] Mar 30, 2021 8:50:59 PM ducis.cleptomania.CmApp start
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB] Exception in Application start method
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB] Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication(LauncherImpl.java:195)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at java.lang.Thread.run(Thread.java:834)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:519)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB] Caused by: java.lang.NoClassDefFoundError: javafx.scene.media.MediaPlayer
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at ducis.cleptomania.core.Music.<init>(Music.java:45)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at ducis.cleptomania.core.Menu.<init>(Menu.java:26)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at ducis.cleptomania.CmApp.start(CmApp.java:60)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1(LauncherImpl.java:846)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait(PlatformImpl.java:455)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:428)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at java.security.AccessController.doPrivileged(AccessController.java:102)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runLater(PlatformImpl.java:427)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_lang_Runnable_2_0002erun_00028_00029V(JNIJavaCallWrappers.java:0)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    at com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
[Di. März 30 20:50:59 MESZ 2021][INFO] [SUB]    ... 3 more
[Di. März 30 20:50:59 MESZ 2021][FINE] Result for run until end: 0

这是我的 pom.xml:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>11</maven.compiler.release>
    <javafx.version>16</javafx.version>
    <attach.version>4.0.11</attach.version>
    <client.plugin.version>0.1.38</client.plugin.version>
    <javafx.plugin.version>0.0.5</javafx.plugin.version>
    <mainClassName>ducis.cleptomania.CmApp</mainClassName>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq</groupId>
        <artifactId>charm-glisten</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>display</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>lifecycle</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>statusbar</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>storage</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>util</artifactId>
        <version>${attach.version}</version>
    </dependency>  
</dependencies>

<repositories>
    <repository>
        <id>Gluon</id>
        <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
    </repository>
</repositories>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>

        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>${javafx.plugin.version}</version>
            <configuration>
                <mainClass>${mainClassName}</mainClass> 
                <options>
                    <option>-agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image</option>
                </options>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.gluonhq</groupId>
            <artifactId>client-maven-plugin</artifactId>
            <version>${client.plugin.version}</version>
            <configuration>
                <target>${client.target}</target>
                <attachList>
                    <list>display</list>
                    <list>lifecycle</list>
                    <list>statusbar</list>
                    <list>storage</list>
                </attachList>
                <mainClass>${mainClassName}</mainClass>
                <nativeImageArgs>
                     <nativeImageArg>-H:+AllowIncompleteClasspath</nativeImageArg>
                     <nativeImageArg>--initialize-at-build-time=javafx.scene.input.KeyCode</nativeImageArg>
                </nativeImageArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>desktop</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <client.target>host</client.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>display</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>lifecycle</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>storage</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>ios</id>
        <properties>
            <client.target>ios</client.target>
        </properties>
    </profile>
    <profile>
        <id>android</id>
        <properties>
            <client.target>android</client.target>
        </properties>
    </profile>
</profiles>

正如 José Pereda 所写:Windows 尚不支持原生图像的媒体和 Web。 我不知道这一点。谢谢!