maven打包exe,免安装jre
时间: 2023-09-24 18:08:48 浏览: 128
可以使用插件`launch4j`来实现将Java程序打包成exe文件,并且不需要安装JRE。
首先,在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>com.mypackage.MyMainClass</mainClass>
<preCp>anything</preCp>
</classPath>
<jre>
<path>jre</path>
<minVersion>1.6.0</minVersion>
<maxVersion>1.8.0</maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64</runtimeBits>
</jre>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
其中,`jar`标签指定了打包的jar文件,`outfile`指定了生成的exe文件名和路径,`classPath`标签中`mainClass`指定了主类,`jre`标签中`path`指定了JRE文件夹路径,`minVersion`和`maxVersion`指定了JRE版本范围,`jdkPreference`指定了优先使用JRE还是JDK,`runtimeBits`指定了运行时位数。
然后,在命令行中执行`mvn package`即可生成exe文件。
阅读全文
相关推荐














