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

求助:基于IntelliJ、Maven、JavaFX与Ikonli生成跨平台可执行Jar

JavaFX + Ikonli Maven项目跨平台可执行文件生成步骤

一、修正Maven POM配置

直接替换项目的<build>块为以下内容,确保依赖打包、模块处理和签名冲突解决都配置到位:

<build>
    <plugins>
        <!-- JavaFX编译运行插件 -->
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <configuration>
                <mainClass>com.meshkatsoft.App</mainClass>
                <modules>
                    <module>javafx.controls</module>
                    <module>javafx.fxml</module>
                </modules>
            </configuration>
        </plugin>
        <!-- Shade插件:打包所有依赖到单个可执行Jar -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.meshkatsoft.App</mainClass>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        </transformers>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- JLink插件:生成自定义JRE镜像,用于原生打包 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jlink-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <moduleName>com.meshkatsoft</moduleName>
                <launcher>app=com.meshkatsoft/com.meshkatsoft.App</launcher>
                <outputDirectory>target/jlink-image</outputDirectory>
                <stripDebug>true</stripDebug>
                <compress>2</compress>
                <noHeaderFiles>true</noHeaderFiles>
                <noManPages>true</noManPages>
            </configuration>
        </plugin>
    </plugins>
</build>

二、生成可执行Jar(跨平台运行需对应JRE)

  1. 打开项目后,点击右侧Maven面板,展开项目的Lifecycle,双击package命令。
  2. 打包完成后,target目录下的Ikonli_Maven-1.0-SNAPSHOT-shaded.jar就是包含所有依赖的可执行Jar。
  3. 运行命令(需本地有JavaFX运行时或对应JRE):
java --module-path "你的/javafx-sdk-19/lib路径" --add-modules javafx.controls,javafx.fxml -jar target/Ikonli_Maven-1.0-SNAPSHOT-shaded.jar

三、生成跨平台原生可执行文件(推荐,无需额外JRE)

原生打包可生成Windows exe、Linux deb/rpm、Mac dmg,需在对应系统上操作:

  1. 确保本地安装JDK 17+(jpackage内置)。
  2. 在Maven面板双击jlink,生成自定义运行时镜像到target/jlink-image。
  3. 打开终端,进入项目根目录执行对应命令:
    • Windows:
    jpackage --name IkonliApp --input target --main-jar Ikonli_Maven-1.0-SNAPSHOT-shaded.jar --runtime-image target/jlink-image --type exe --win-console
    
    • Linux:
    jpackage --name IkonliApp --input target --main-jar Ikonli_Maven-1.0-SNAPSHOT-shaded.jar --runtime-image target/jlink-image --type deb
    
    • Mac:
    jpackage --name IkonliApp --input target --main-jar Ikonli_Maven-1.0-SNAPSHOT-shaded.jar --runtime-image target/jlink-image --type dmg --mac-sign
    
  4. 生成的文件在项目根目录,直接运行即可。

注意事项

  • 确认POM中mainClass路径与项目实际主类一致(你的项目是com.meshkatsoft.App)。
  • 若打包时出现签名冲突,检查Shade插件的filter配置是否排除了签名文件。
  • 跨平台原生打包需在对应系统执行,比如生成exe要在Windows机器上操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 18:45:19