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>
相关推荐
南 阳43 分钟前
Python从入门到精通day66
开发语言·python
好家伙VCC1 小时前
【无标题】
java
十八旬2 小时前
快速安装ClaudeCode完整指南
开发语言·windows·python·claude
前进的李工2 小时前
EXPLAIN输出格式全解析:JSON、TREE与可视化
开发语言·数据库·mysql·性能优化·explain
小碗羊肉2 小时前
【JavaWeb | 第十一篇】文件上传(本地&阿里云OSS)
java·阿里云·servlet
吾疾唯君医2 小时前
Java SpringBoot集成积木报表实操记录
java·spring boot·spring·导出excel·积木报表·数据文件下载
Byron Loong3 小时前
【c++】为什么有了dll和.h,还需要包含lib
java·开发语言·c++
独隅3 小时前
CodeX + Visual Studio Code 联动的全面指南
开发语言·php
坚果派·白晓明3 小时前
【鸿蒙PC三方库移植适配框架解读系列】第一篇:Lycium C/C++ 三方库适配 — 概述与环境配置
c语言·开发语言·c++·harmonyos·开源鸿蒙·三方库·c/c++三方库
hexu_blog3 小时前
vue+java实现图片批量压缩
java·前端·vue.js