maven打包成exe,免安装jdk8
时间: 2023-10-23 20:12:29 浏览: 109
你可以使用插件将Maven打包成可执行文件(exe),并将JRE(Java运行时环境)嵌入到exe文件中,以便用户无需安装JRE即可运行程序。
以下是使用launch4j插件将Maven项目打包成exe文件的步骤:
1.在pom.xml文件中添加以下插件:
```xml
<build>
<plugins>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.25</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
<outfile>${project.build.directory}/${project.build.finalName}.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>${project.groupId}.${project.artifactId}.MainClass</mainClass>
<preCp>anything</preCp>
</classPath>
<jre>
<path>jre</path>
<minVersion>1.8.0</minVersion>
<initialHeapSize>128</initialHeapSize>
<maxHeapSize>512</maxHeapSize>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
注意:修改mainClass节点的值为你的主类名。
2.在Maven项目根目录下创建jre文件夹,并将JRE文件夹中的所有文件复制到该文件夹中。
3.执行以下命令打包项目:`mvn clean package`
4.在target目录下将生成exe文件,即可执行文件。
注意:在打包前请确保本地已经安装了launch4j和JRE。如果没有安装,可以在launch4j官网(https://launch4j.sourceforge.io/)下载安装包进行安装。
阅读全文
相关推荐


















