0

Based on the tip in https://stackoverflow.com/a/52142071 I managed to get my app to compile and start without the "cannot access class" errors. But now I run into the following exception when trying to initialize the 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)

I haven't found anything on this exception so far. Any idea what to do here?

Java 11.0.1 with JavaFX 11.0.1, Win10 64bit

EDIT

Sorry, somehow I thought it happens in all possible combinations but that doesn't seem to be the case... So here some more info.

NOT WORKING when running the following in Netbeans:

  • Apache NetBeans IDE 9.0 (Build incubator-netbeans-release-334-on-20180708)
  • Groovy Plugin 1.35
  • Gradle Plugin 2.0.1
  • Gradle 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',
        ]
    }
}

WORKING when running the following on the command line:

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
  • If you are using _several_ JavaFX modules, why don't you add them to the `compileJava` and `run` tasks to the `--add-modules` parameter? Check this [answer](https://stackoverflow.com/a/52907749/3956070) with same issue. – José Pereda Nov 10 '18 at 14:36
  • Note also that after you add the modules, you won't need to add the long list of `--add-exports`. – José Pereda Nov 10 '18 at 14:39
  • I could make it work be adding various to the `--add-modules` parameter. But I still need the many `--add-exports` as in https://stackoverflow.com/a/52142071 – ThomasDaheim Nov 10 '18 at 21:25
  • Can you try this [sample](https://github.com/openjfx/samples/tree/master/IDE/NetBeans/Non-Modular/Gradle)? It is a very simple app with controls and fxml modules, but it doesn't require `--add-exports`. – José Pereda Nov 10 '18 at 21:38
  • Your example works for me. Obviously, I'm using something that requires the `--add-exports` in my code. E.g. controlsfx, in their `ControlsFXControl.`method the first missing export appears – ThomasDaheim Nov 11 '18 at 20:49
  • BTW, in your example the `Debug` gradle tasks fails - same as in my application... Will open an issue in github for that. – ThomasDaheim Nov 11 '18 at 20:51
  • Now you could create a very simple gradle project: a module that `requires javafx.base`, and has just a class with a JavaFX property, and getters/setters.Then add this module as a requirement of the HelloFX sample? Would that work for you or will IntelliJ still complain with the same error? – José Pereda Nov 11 '18 at 22:15
  • Why not start with a real life example :-) I have added a RangeSlider from controlsfx 9.0.0. to the HelloFX pane. With only that I need 4 (!) `--add-exports` to make it run again. – ThomasDaheim Nov 14 '18 at 19:59

0 Answers0