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

GluonFX打包含WebView的JavaFX程序为Windows原生镜像报ClassNotFoundException

问题解决方法

根因说明

GluonFX 1.0.3版本默认不会主动识别并打包javafx.web模块的类与WebView依赖的WebKit本地资源,同时旧版插件对Windows平台WebView原生镜像的适配存在缺陷,导致运行时找不到javafx.scene.web.WebView类。

修复步骤

1. 升级依赖版本

修改pom.xml中的properties配置,替换为兼容WebView的版本:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>17</maven.compiler.release>
    <javafx.version>17.0.8</javafx.version>
    <attach.version>4.0.18</attach.version>
    <gluonfx.plugin.version>1.0.18</gluonfx.plugin.version>
    <javafx.plugin.version>0.0.8</javafx.plugin.version>
    <mainClassName>com.gluonapplication.GluonApplication</mainClassName>
</properties>

2. 调整GluonFX插件配置

在gluonfx-maven-plugin的configuration节点中添加WebKit支持配置,主动开启WebView打包逻辑:

<plugin>
    <groupId>com.gluonhq</groupId>
    <artifactId>gluonfx-maven-plugin</artifactId>
    <version>${gluonfx.plugin.version}</version>
    <configuration>
        <target>${gluonfx.target}</target>
        <attachList>
            <list>display</list>
            <list>lifecycle</list>
            <list>statusbar</list>
            <list>storage</list>
        </attachList>
        <mainClass>${mainClassName}</mainClass>
        <!-- 新增以下两行配置 -->
        <javafxStaticSdkVersion>${javafx.version}</javafxStaticSdkVersion>
        <enableWebKit>true</enableWebKit>
    </configuration>
</plugin>

3. 新增模块描述文件(可选,解决无名模块警告)

在src/main/java目录下新建module-info.java,内容如下:

module com.gluonapplication {
    requires javafx.controls;
    requires javafx.web;
    requires com.gluonhq.charm.glisten;
    requires com.gluonhq.attach.display;
    requires com.gluonhq.attach.lifecycle;
    requires com.gluonhq.attach.statusbar;
    requires com.gluonhq.attach.storage;
    exports com.gluonapplication to javafx.graphics;
}

4. 重新构建测试

依然使用VS 2019的x64 Native Tools Prompt终端执行构建命令:
mvn clean gluonfx:build gluonfx:nativerun
构建完成后会自动启动生成的原生exe,可正常加载WebView打开目标网页。


内容的提问来源于stack exchange,提问作者Rocco Trigiante

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 09:06:04