java 打包exe maven 版本

第一次

maven 加入本地包

system

D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA-SecX2.7.1/3.0/BJCA-SecX2.7.1-3.0.jar

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.sky</groupId>
    <artifactId>easyexceltest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>

        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.3.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.52</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-SecX2.7.1</artifactId>
            <version>3.0</version>
            <scope>system</scope>
            <systemPath>D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA-SecX2.7.1/3.0/BJCA-SecX2.7.1-3.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE2</artifactId>
            <version>2.0</version>
            <scope>system</scope>
            <systemPath>D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA-JCE2/2.0/BJCA-JCE2-2.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JDOM</artifactId>
            <version>2.0</version>
            <scope>system</scope>
            <systemPath>D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA-JDOM/2.0/BJCA-JDOM-2.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA_multi_LOG_1.4</artifactId>
            <version>2.0</version>
            <scope>system</scope>
            <systemPath>D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA_multi_LOG_1.4/2.0/BJCA_multi_LOG_1.4-2.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE</artifactId>
            <version>2.0</version>
            <scope>system</scope>
            <systemPath>D:/apache-maven-3.9.8/repository/com/cpic/ca/BJCA-JCE/2.0/BJCA-JCE-2.0.jar</systemPath>
        </dependency>
    </dependencies>
    <build>
        <finalName>SM4Tool</finalName>
        <plugins>
            <!-- 1. 打可执行jar,指定主类 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!-- 2. 把本地jar包打进jar里(关键!) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

生成jar mvn clean package

安装 加入环境变量path

https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip

jpackage 生成exe

jpackage --input . --main-jar SM4Tool-jar-with-dependencies.jar --main-class dao.hellowrold --name SM4工具 --win-console

第二次

文件放到 maven repository 路径下 D:\apache-maven-3.9.8\repository

不需要设置:scope、systemPath

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.sky</groupId>
    <artifactId>easyexceltest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>

        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.3.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.52</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-SecX2.7.1</artifactId>
            <version>3.0</version>
       </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE2</artifactId>
            <version>2.0</version>
       </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JDOM</artifactId>
            <version>2.0</version>
       </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA_multi_LOG_1.4</artifactId>
            <version>2.0</version>
       </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE</artifactId>
            <version>2.0</version>
       </dependency>
    </dependencies>
    <build>
        <finalName>SM4Tool</finalName>
        <plugins>
            <!-- 1. 打可执行jar,指定主类 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!-- 2. 把本地jar包打进jar里(关键!) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
bash 复制代码
#生成jar 
mvn clean package 
#运行java
java -jar G:\JSH_ERP\easyexceltest\target\SM4Tool-jar-with-dependencies.jar

第三次 launch4j 打包exe

先下载 launch4j

https://sourceforge.net/projects/launch4j/files/latest/download

maven 里面加入这个

xml 复制代码
 <!-- ====================== Launch4j 插件 ====================== -->
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>2.3.0</version>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <jar>target/SM4Tool-jar-with-dependencies.jar</jar>
                            <outfile>target/SM4加密工具.exe</outfile>
                            <classPath>
                                <mainClass>dao.hellowrold</mainClass>
                            </classPath>
                            <jre>
                                <path>%JAVA_HOME%</path>
                                <bundledJre64Bit>true</bundledJre64Bit>
                                <runtimeBits>64</runtimeBits>
                                <minVersion>17</minVersion>
                                <maxVersion>21</maxVersion>
                            </jre>
                            <!-- 关键:修复版本信息报错 -->
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>1.0</txtFileVersion>
                                <fileDescription>SM4加密解密工具</fileDescription>
                                <copyright>copyright</copyright>
                                <productVersion>1.0.0.0</productVersion>
                                <txtProductVersion>1.0</txtProductVersion>
                                <productName>SM4工具</productName>
                                <companyName>test</companyName>
                                <internalName>SM4Tool</internalName>
                                <originalFilename>SM4工具.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

完整版

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.sky</groupId>
    <artifactId>easyexceltest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>

        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.3.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.52</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-SecX2.7.1</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE2</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JDOM</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA_multi_LOG_1.4</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>com.cpic.ca</groupId>
            <artifactId>BJCA-JCE</artifactId>
            <version>2.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>SM4Tool</finalName>
        <plugins>
            <!-- 1. 打可执行jar,指定主类 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!-- 2. 把本地jar包打进jar里(关键!) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>dao.hellowrold</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- ====================== Launch4j 插件 ====================== -->
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>2.3.0</version>
                <executions>
                    <execution>
                        <id>l4j-clui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <jar>target/SM4Tool-jar-with-dependencies.jar</jar>
                            <outfile>target/SM4加密工具.exe</outfile>
                            <classPath>
                                <mainClass>dao.hellowrold</mainClass>
                            </classPath>
                            <jre>
                                <path>%JAVA_HOME%</path>
                                <bundledJre64Bit>true</bundledJre64Bit>
                                <runtimeBits>64</runtimeBits>
                                <minVersion>17</minVersion>
                                <maxVersion>21</maxVersion>
                            </jre>
                            <!-- 关键:修复版本信息报错 -->
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>1.0</txtFileVersion>
                                <fileDescription>SM4加密解密工具</fileDescription>
                                <copyright>copyright</copyright>
                                <productVersion>1.0.0.0</productVersion>
                                <txtProductVersion>1.0</txtProductVersion>
                                <productName>SM4工具</productName>
                                <companyName>test</companyName>
                                <internalName>SM4Tool</internalName>
                                <originalFilename>SM4工具.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
相关推荐
MuzySuntree1 小时前
Ubuntu 下 Maven 构建 Spring Boot 项目报错 release version 17 not supported 解决方案
spring boot·ubuntu·maven
兩尛1 小时前
C++面向对象和类相关
java·c++·面试
changshuaihua0012 小时前
useState 状态管理
开发语言·前端·javascript·react.js
聆风吟º2 小时前
【Python编程日志】Python入门基础(二):行 | 缩进 | print输出
开发语言·python·print··缩进
ch.ju2 小时前
Java程序设计(第3版)第二章——循环结构(3)
java
再玩一会儿看代码2 小时前
idea中快捷键详细总结整理
java·ide·经验分享·笔记·学习·intellij-idea
lsx2024062 小时前
Servlet 点击计数器
开发语言
卷心菜狗2 小时前
Python进阶-闭包与装饰器
开发语言·python·学习
IT光2 小时前
IDEA 2026.1 配置属性识别问题解决
java·ide·intellij-idea