Springboot window項目打包成exe

要打包的話,依然是maven,固然要跳過test,不然依然會報錯java.awt.headlessException,java

idea中跳過測試只須要點一個按鈕,如圖spring

就是上排圖片倒數第4個apache

而後在pom中加入以下代碼springboot

<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>,你能夠加上less

<dependency>
   <groupId>com.akathist.maven.plugins.launch4j</groupId>
   <artifactId>launch4j-maven-plugin</artifactId>
   <version>1.7</version>
</dependency>

丟到依賴裏面,從新加載,等加載完了再刪了這個依賴。maven

要改的地方就是兩個<mainClass></mainClass>改爲你本身的springboot主類,另外加一個0.ico的圖片放到<icon>src/main/resources/0.ico</icon>,點package,生成的exe以下圖ide

相關文章
相關標籤/搜索