javafx11 java.lang.ClassNotFoundException:带有WebView的com.sun.media.jfxmedia.events.PlayerStateListener

时间:2018-11-08 20:41:23

标签: javafx java-11

基于https://stackoverflow.com/a/52142071中的技巧,我设法使我的应用程序得以编译并启动,而没有出现“无法访问类”错误。但是现在尝试初始化Webview时遇到以下异常:

Caused by: java.lang.NoClassDefFoundError: com/sun/media/jfxmedia/events/PlayerStateListener
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at javafx.scene.web.WebEngine.<clinit>(WebEngine.java:341)
    at javafx.scene.web.WebView.<init>(WebView.java:260)
    at com.sun.javafx.fxml.builder.web.WebViewBuilder.build(WebViewBuilder.java:66)

到目前为止,我还没有发现任何关于此异常的信息。知道在这里做什么吗?

带有JavaFX 11.0.1,Win10 64位的Java 11.0.1

编辑

对不起,我以某种方式认为它会在所有可能的组合中发生,但事实并非如此……所以这里有更多信息。

在Netbeans中运行以下命令时不起作用:

  • Apache NetBeans IDE 9.0(在20180708上构建incubator-netbeans-release-334-on)
  • Groovy插件1.35
  • Gradle插件2.0.1
  • 4.10.2级

build.gradle:

// support for javafx11 - see https://openjfx.io/openjfx-docs/#gradle
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gradle:osdetector-gradle-plugin:1.6.0'
    }
}

// Use a plugin (https://github.com/crotwell/gradle-macappbundle) to create a Mac OS X .app and .dmg
plugins {
    id "edu.sc.seis.macAppBundle" version "2.1.5"
}

macAppBundle {
    mainClassName = "tf.ownnote.ui.main.OwnNoteEditorManager"
    icon          = "src/main/resources/ownNoteEditor.icns"
    volumeName    = "ownNoteEditor"
    dmgName       = "ownNoteEditor"
    javaProperties.put("apple.laf.useScreenMenuBar", "true")
    // Uncomment the next line to bundle the JRE with the Mac OS X application
    //bundleJRE     = true
}

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.google.osdetector'

mainClassName = 'tf.ownnote.ui.main.OwnNoteEditorManager'

ext.platform = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile "org.openjfx:javafx-base:11:$platform"
    compile "org.openjfx:javafx-graphics:11:$platform"
    compile "org.openjfx:javafx-controls:11:$platform"
    compile "org.openjfx:javafx-fxml:11:$platform"
    compile "org.openjfx:javafx-swing:11:$platform"
    compile "org.openjfx:javafx-web:11:$platform"

    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.12'
    compile 'commons-cli:commons-cli:1.3.1'
    compile 'commons-io:commons-io:2.4'
    compile 'org.apache.commons:commons-lang3:3.5'
    compile group: 'org.openjfx', name: 'javafx-controls', version: '11'
    compile group: 'org.openjfx', name: 'javafx-fxml', version: '11'
    compile group: 'org.openjfx', name: 'javafx-web', version: '11'
    compile group: 'org.openjfx', name: 'javafx-swing', version: '11'

    testCompile "org.testfx:testfx-junit:4.0.+"
    testCompile "org.testfx:testfx-core:4.0.+"
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.1'
}

compileJava {
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls',
                '-Xlint:unchecked',
                '-Xlint:deprecation',
        ]
    }
}

run {
    doFirst {
        jvmArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls',
                // various exports needed at run time - see https://stackoverflow.com/a/52142071
                '--add-exports', 'javafx.graphics/com.sun.javafx.util=ALL-UNNAMED',
                '--add-exports', 'javafx.base/com.sun.javafx.reflect=ALL-UNNAMED',
                '--add-exports', 'javafx.base/com.sun.javafx.beans=ALL-UNNAMED',
                '--add-exports', 'javafx.base/com.sun.javafx.logging=ALL-UNNAMED',
                '--add-exports', 'javafx.graphics/com.sun.prism=ALL-UNNAMED',
                '--add-exports', 'javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED',
                '--add-exports', 'javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
                '--add-exports', 'javafx.media/com.sun.media.jfxmedia=ALL-UNNAMED',
                '--add-exports', 'javafx.media/com.sun.media.jfxmedia.events=ALL-UNNAMED',
        ]
    }
}

在命令行上运行以下命令时会起作用:

set CLASSPATH=%APP_HOME%\lib\ownNoteEditor.jar;%APP_HOME%\lib\slf4j-api-1.7.12.jar;%APP_HOME%\lib\commons-cli-1.3.1.jar;%APP_HOME%\lib\commons-io-2.4.jar;%APP_HOME%\lib\commons-lang3-3.5.jar

"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %OWN_NOTE_EDITOR_OPTS% -classpath "%CLASSPATH%" --module-path %PATH_TO_FX%/lib --add-modules=javafx.controls,javafx.graphics,javafx.base,javafx.fxml,javafx.web,javafx.swing tf.ownnote.ui.main.OwnNoteEditorManager

0 个答案:

没有答案