maven打包exe,免安装jre
时间: 2023-09-24 20:08:47 浏览: 177
要将Java应用程序打包为可执行的exe文件,可以使用Apache Maven插件,如launch4j或exe4j。
其中,launch4j插件可以将jar文件打包成exe文件,同时可以指定JRE的路径,从而实现免安装JRE的效果。具体步骤如下:
1. 在pom.xml文件中添加launch4j插件的配置:
```
<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>path/to/jre</path>
<minVersion>1.8.0</minVersion>
<maxVersion>1.8.0</maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
其中,jar、outfile、mainClass等参数需要根据实际情况进行修改。jre节点用于指定JRE的路径和版本。
2. 运行mvn package命令,即可生成exe文件。exe文件会输出到target目录下。
注意:launch4j插件需要在Windows系统上运行,因为它需要使用Windows本地库。如果需要在其他操作系统上运行,请使用其他插件如exe4j。
阅读全文