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>
相关推荐
蛋蛋的就会顺顺的6 小时前
hot100 p0——栈,贪心算法,动态规划
java·前端·javascript·算法·leetcode·力扣
需要8267 小时前
Spring Bean 生命周期:从实例化到销毁的完整钩子
java·后端·spring
小 黄 鸡7 小时前
HashMap 面试必会知识点详解(JDK 8)
java·面试·职场和发展
死磕音视频7 小时前
让小模型做选择题:限定候选项并读取 logits 概率的入门实践(附 Python 代码)
开发语言·python·大模型·文本分类·transformers
伯恩bourne9 小时前
Spring Boot Bean 注册的两种方式:@Component 家族 vs @Configuration + @Bean
java·spring boot·后端
silvamux_9 小时前
curl 测试 OpenAI 兼容 API 的完整流程
java·人工智能·缓存·ai·oneapi
省钱兄--zs10 小时前
深圳24小时自助健身房软硬件解决方案实战指南与开发流程详解
java·数据仓库·spring boot·小程序·架构
顽疲10 小时前
Java vue 养老系统源码详解:月账单 care_month_bill 与 Quartz 扣费 Job 实践
java·开发语言·vue.js·vue养老·springboot养老·java养老
Wang's Blog10 小时前
Java 项目实战: 交友项目 - 安装开发工具与环境准备
java·开发语言·交友
用户212968352616810 小时前
开源了一个 Java 多智能体 LLM 框架 Baton:一个依赖,把 Agent 循环、工具调用、记忆、编排全配齐
java·llm