1. 写在前面
基于Maven
,引入shade
和launch4j
工具,将一个gui
程序打包生成exe
文件。
2. 配置
- 配置
MainClass
:com.music.player.App
- 指定
JRE
为当前目录:./jre
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.music.player.App</mainClass>
</transformer>
</transformers>
</configuration>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${project.build.directory}/${artifactId}-${version}-shaded.jar</jar>
<outfile>${project.build.directory}/sunye.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>com.music.player.App</mainClass>
<preCp>anything</preCp>
</classPath>
<!-- <icon>src/resources/0.ico</icon> -->
<jre>
<minVersion>1.8.0</minVersion>
<path>./jre</path>
<jdkPreference>jdkOnly</jdkPreference>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>2021 sunye.com</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<companyName>sunye.com</companyName>
<internalName>sunye</internalName>
<originalFilename>sunye.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
3. 生成
运行Maven
命令:package
,生成exe
文件。(上面配置的outfile
。)
复制本地jre
和生成的exe
文件组成最终成品。
-- sunye
---- jre
---- sunye.exe