You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中无法为Maven项目添加javafx.web依赖的求助

Troubleshooting JavaFX Web Dependency Issues in VS Code with Maven

Hey there! Let's work through this JavaFX web dependency issue together. I've looked over your setup, and there are a few small but critical fixes we can make to get HTMLEditor working properly—no need to manually add JAR files when Maven can handle this cleanly.

Key Problems & Fixes:

1. Missing Module Declaration in module-info.java

Your module descriptor doesn't include a dependency on the javafx.web module, which is mandatory to use HTMLEditor. Update it like this:

module dylan.gresham {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.web; // Add this line to enable web module
    requires transitive javafx.graphics;

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

2. Mismatched JavaFX Versions

Your pom.xml uses JavaFX 19, but your VM arguments point to the 18.0.1 SDK. Mixing versions causes compatibility issues—pick one version and stick with it:

  • If you want to use v19: Download the JavaFX 19 SDK and update your VM arguments to point to its lib folder
  • If you prefer v18.0.1: Update all JavaFX dependency versions in your pom.xml to 18.0.1

3. Invalid VM Argument Syntax

Your current VM arguments have syntax errors that break module resolution. Fix it to target only the modules you need:

--module-path "C:\Users\dylan\Downloads\JavaFX\javafx-sdk-19\lib" --add-modules javafx.controls,javafx.fxml,javafx.web

(Replace the path with your actual JavaFX SDK lib directory, matching your chosen version)

4. Use the Maven JavaFX Plugin for Running

Since you've already configured the javafx-maven-plugin, skip manual VM argument setup in VS Code. Instead, run your project via terminal with:

mvn clean javafx:run

The plugin automatically handles module path and module additions, eliminating manual configuration mistakes.

5. Don't Manually Add JAR Files

Manually adding javafx.web.jar from the SDK is not recommended. Maven's dependency management ensures you get compatible versions and handles transitive dependencies automatically, keeping your project clean and maintainable.

Your Updated Configuration Files (for reference)

Your pom.xml is already mostly correct—just ensure JavaFX versions match your SDK. Here's the original pom.xml formatted properly:

<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>

Try these fixes, and you should be able to use HTMLEditor without issues. Let me know if you hit any other snags!

内容的提问来源于stack exchange,提问作者Dylan Gresham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 18:35:25