0

I'm new to maven and java projects as a whole and I've been trying to add javafx.web to my Maven project, specifically for the HTMLEditor class, on VS Code and so far have been unable to.

I've added the dependency to the pom.xml file and put in VM Arguments that lead to my installation of JavaFX and nothing has worked.

Is there a way to do this that I'm missing or would it be better to just add a copy of the javafx.web.jar that is in the JavaFX\javafx-sdk\lib folder directly somehow?

My pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>dylan.gresham</groupId>
    <artifactId>nottah</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>19</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>dylan.gresham.Main</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <transformers>
                                <transformer implementation=
                                                     "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>dylan.gresham.Driver</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

My VM Arguments:

--module-path C:\Users\dylan\Downloads\JavaFX\javafx-sdk-18.0.1\lib --add-modules =ALL -MODULE-PATH

My module-info.java:

module dylan.gresham {
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;

    opens dylan.gresham to javafx.fxml;
    exports dylan.gresham;
}

Edit: Added module-info file above.

  • What specifically do you mean by “it doesn’t work”? Compile error? Runtime error? What are the specific errors? Is this a modular project? If so, what’s in your module-info.java file? – James_D Jan 12 '23 at 01:07
  • @James_D Doesn't work as in I am still unable to import javafx.scene.web or javafx.scene.web.HTMLEditor. I get the messages "The package javafx.scene.web is not accessible" and "The type javafx.scene.web.HTMLEditor is not accessible". It is a modular project and I've added the module-info.java file above. – Dylan Gresham Jan 12 '23 at 01:12
  • You need to add `requires javafx.web;` to module-info.java – James_D Jan 12 '23 at 01:16
  • In the [openjfx getting started documentation](https://openjfx.io/openjfx-docs/) for "JavaFX and Visual Studio Code: modular with Maven". It recommends running the app via the maven JavaFX plugin, not by VM arguments to use the JavaFX SDK. That would seem safer than running for the SDK downloaded as it would be less error prone. For example, you are compiling using Maven Java modules version 19, but executing using the JavaFX SDK lib 18.0.1. This suggestion is unrelated to the fix to add `javafx.web` to `module-info.java`, which is required in any case. – jewelsea Jan 12 '23 at 06:38

1 Answers1

1

As pointed out by @James_D I needed to add requires javafx.web; to my module-info.java file. After adding that line I was able to import what I needed to.