Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebConsoleListener IllegalAccessError in JavaFX 12

Tags:

javafx

I recently downloaded the latest JavaFX SDK 12 and I wish to intercept Console Messages in my JavaFX WebView.

So, I have this

WebConsoleListener.setDefaultListener((webView, message, lineNumber, sourceId) -> {
       //////// I am listening for a specific console message here in my 
      ///webview
  });

but I keep getting


Caused by: java.lang.IllegalAccessError: class rumbler.launcher.ApplicationLoader (in unnamed module @0x5c4c6905) cannot access class com.sun.javafx.webkit.WebConsoleListener (in module javafx.web) because module javafx.web does not export com.sun.javafx.webkit to unnamed module @0x5c4c6905

Here is my build.gradle file

javafx {
    version = "12.0.1"
    modules = ['javafx.base', 'javafx.controls', 'javafx.web']
}

Here are my VM OPTIONS

--module-path "path_to_\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.web,javafx.base

.Am I missing something?

like image 813
mekings Avatar asked Dec 06 '25 14:12

mekings


1 Answers

You are using private API, which is not advised.

Anyway, the error message is quite clear:

module javafx.web does not export com.sun.javafx.webkit to unnamed module @0x5c4c6905

Whenever you want to access some non-exposed package from your project (either modular on non-modular), you need to use --add-exports:

The command line option --add-exports $module/$package=$readingmodule exports $package of $module to $readingmodule. Code in $readingmodule can hence access all public types in $package but other modules can not. [source].

So in this case, the solution is straight forward:

--add-exports javafx.web/com.sun.javafx.webkit=ALL-UNNAMED \
--module-path "path_to_\javafx-sdk-11.0.2\lib" \
--add-modules javafx.web,javafx.fxml
like image 131
José Pereda Avatar answered Dec 10 '25 07:12

José Pereda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!