前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springboot window项目打包成exe

Springboot window项目打包成exe

作者头像
算法之名
发布2019-08-20 11:06:21
2.2K1
发布2019-08-20 11:06:21
举报
文章被收录于专栏:算法之名算法之名

要打包的话,依然是maven,当然要跳过test,否则依然会报错java.awt.headlessException,

idea中跳过测试只需要点一个按钮,如图

就是上排图片倒数第4个

然后在pom中加入如下代码

代码语言:javascript
复制
<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
            <source>1.7</source>
            <target>1.7</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>
               <transformer
                     implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.guanjian.SpringnettyApplication</mainClass>
               </transformer>
         </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}/hasCode.exe</outfile>
                  <downloadUrl>http://java.com/download</downloadUrl>
                  <classPath>
                     <mainClass>com.guanjian.SpringnettyApplication</mainClass>
                     <preCp>anything</preCp>
                  </classPath>
                  <icon>src/main/resources/0.ico</icon>
                  <jre>
                     <minVersion>1.7.0</minVersion>
                     <jdkPreference>preferJre</jdkPreference>
                  </jre>
                  <versionInfo>
                     <fileVersion>1.0.0.0</fileVersion>
                     <txtFileVersion>${project.version}</txtFileVersion>
                     <fileDescription>${project.name}</fileDescription>
                     <copyright>2012 hasCode.com</copyright>
                     <productVersion>1.0.0.0</productVersion>
                     <txtProductVersion>1.0.0.0</txtProductVersion>
                     <productName>${project.name}</productName>
                     <companyName>hasCode.com</companyName>
                     <internalName>hasCode</internalName>
                     <originalFilename>hasCode.exe</originalFilename>
                  </versionInfo>
               </configuration>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>

如果找不到<groupId>com.akathist.maven.plugins.launch4j</groupId> <artifactId>launch4j-maven-plugin</artifactId>,你可以加上

代码语言:javascript
复制
<dependency>
   <groupId>com.akathist.maven.plugins.launch4j</groupId>
   <artifactId>launch4j-maven-plugin</artifactId>
   <version>1.7</version>
</dependency>

丢到依赖里面,重新加载,等加载完了再删了这个依赖。

要改的地方就是两个<mainClass></mainClass>改成你自己的springboot主类,另外加一个0.ico的图片放到<icon>src/main/resources/0.ico</icon>,点package,生成的exe如下图

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档