使用maven将Java程序打包成exe文件并制作成Windows系统服务之springboot打包exe并绑定jdk
在Spring Boot项目中,要将应用打包成exe文件并创建为Windows服务,可以使用spring-boot-maven-plugin
插件和launch4j-maven-plugin
插件。以下是pom.xml
中的配置示例:
<build>
<plugins>
<!-- Spring Boot Maven Plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Launch4j Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<dontWrap>false</dontWrap>
<headerType>gui</headerType>
<outfile>${project.build.directory}/${project.artifactId}-${project.version}.exe</outfile>
<classPath>
<mainClass>com.example.YourApplication</mainClass>
</classPath>
<icon>src/main/resources/your-icon.ico</icon>
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
<chdir>${project.build.directory}</chdir>
<downloadUrl>http://java.com/downloads/</downloadUrl>
<installDir>${project.installDir}</installDir>
<keepTemp>false</keepTemp>
<maxHeapSize>256</maxHeapSize>
<outputDir>${project.build.directory}</outputDir>
<preCleanupHelperScript>src/main/resources/pre-cleanup.bat</preCleanupHelperScript>
<preExtractHelperScript>src/main/resources/pre-extract.bat</preExtractHelperScript>
<preInitHelperScript>src/main/resources/pre-init.bat</preInitHelperScript>
<renameJar>false</renameJar>
评论已关闭