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

使用IntelliJ+Gradle构建JavaFX可执行FatJar出现模块报错如何解决?

修复步骤

  1. 先删除所有你手动添加的module-info.java文件,非模块化JavaFX项目不需要该文件,最初的"no module-info.java found"报错是老版本插件兼容问题导致,不是真的需要创建该文件。
  2. 替换你的build.gradle内容为以下配置,主要做了三处调整:升级JavaFX插件到稳定版本、添加重复文件处理规则、排除所有无用的module-info.class文件:
plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.1.0'
}

repositories {
    mavenCentral()
}

dependencies {
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:win"
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:linux"
    runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:mac"
}

javafx {
    version = "16"
    modules = [ 'javafx.controls' ]
}

// 此处修改为你的启动器类的全限定名,和manifest中配置保持一致
mainClassName = 'main.class.with.Launcher'

jar {
    manifest {
        attributes 'Main-Class': 'main.class.with.Launcher'
    }
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    exclude 'module-info.class'
}
  1. 执行打包命令:
./gradlew clean jar

生成的可执行jar包位于项目build/libs目录下,使用java -jar 生成的jar包名.jar即可直接运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 10:24:04