3

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?

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

2 Comments

Note: when adding exports at the command line: if your application provides a module-info.java file, then use the name of your application module from the module-info.java file, instead of ALL-UNNAMED. For more info, see the the related question: How to get the JavaFx WebEngine to report errors in details?.
To address "You are using private API, which is not advised." I want to mention related question "What is the public API for getting JavaFX WebView console events?", which I believe is the better canonical question/answer. (TL;DR: no code API available in 2022, but logging framework can be configured to emit same messages)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.