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>
相关推荐
码途行者3 分钟前
每天10分钟学Go:第22课 自定义错误
开发语言·后端·golang
23图17 分钟前
C 语言开散列表(拉链法)拆解:链挂得没错,key=-1 会去读 T[-1]
c语言·开发语言·散列表
feixing_fx1 小时前
解构与展开:可读性和性能的取舍
开发语言·前端·javascript·前端框架
小飞在努力1 小时前
【实现负载均匀在线判题③】从零散模块到统一,编译运行全链路封装
c语言·开发语言·c++·笔记
Flynt2 小时前
Spring AI Alibaba 真停更了?我把它的 GitHub 翻了个底朝天
java·spring·开源
饮水桶_T5 小时前
C++ stack & queue复习笔记
开发语言·笔记·算法
她的男孩5 小时前
Spring Boot 接 Flowable:请假单要同时走财务和行政,包容分支和默认分支怎么配
java·spring boot·工作流引擎
炸膛坦客5 小时前
单片机/C/C++八股:(三十四)C 语言函数参数入栈顺序
c语言·开发语言·c++
咖啡八杯6 小时前
LoginUser 适配器模式:适配 SysUser 到 UserDetails
java·开发语言·后端·框架·适配器模式·若依
bufengwangluo7 小时前
企业上网行为管理:代理网关部署位置怎么选,策略怎么落
开发语言·php