6

Using Intellij 2021.3.2, JavaFX version: 11.0.2+1.

I'm trying to add a JavaFX WebView to my application. My import statement does not compile:

import javafx.scene.web;  

The compilation error:

java: cannot find symbol symbol: class web location: package javafx.scene

As far as I can tell, JavaFX version 11 should contain the .web package. Maybe I have to install something specific to use it?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Troy Cowan
  • 69
  • 1
  • 2
  • 2
    make sure the module javafx.web is added to build/runtime module path – kleopatra Feb 01 '22 at 16:22
  • Does this answer your question? [Module error when running JavaFx media application](https://stackoverflow.com/questions/53237287/module-error-when-running-javafx-media-application) – kleopatra Feb 01 '22 at 16:23
  • That sounds like good advice. How do I do that? Is that an intellij setting or a java setting, or what? – Troy Cowan Feb 01 '22 at 17:20

1 Answers1

5

This is one way to do it:

  1. Create a new JavaFX project.
  2. Edit pom.xml.
  3. Add a dependency on javafx-web.
    • Use the same version as the rest of the JavaFX dependencies in that file.
    • Hit the refresh icon in the maven window to re-synchronize the Maven project with the IDE project.
  4. Edit module-info.java.
  5. Add the line requires javafx.web;.

Example POM excerpt:

…
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>20.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>20.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-web -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>20.0.2</version>
        </dependency>
…

Example module-info.java:

module com.example.exfxwebview {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.web;


    opens com.example.exfxwebview to javafx.fxml;
    exports com.example.exfxwebview;
}

You will now be able to use WebView in your code.


Alternatively, take your existing project, follow the advice in the answer kleopatra linked:

and add in the javafx.web module where-ever that answer refers to adding modules.

The answer is similar to the following which discusses the javafx.media module:

I advise using the most recent stable version of Java and JavaFX for development, currently 20.0.2, not JavaFX 11, especially if you have a Mac with Apple Silicon (M1, M2). Only JavaFX 17.0.2+ works with those Macs.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
jewelsea
  • 150,031
  • 14
  • 366
  • 406