spring boot 打包為單給jar 檔案普遍過大,在而本身項目代碼占比較小。y
參考
https://blog.csdn.net/qq_36732557/article/details/79242414
https://dzone.com/articles/packaging-springboot-application-with-external-dep 這個還是打包了單個大包
在以上文章的基礎上進行了整合
目标:
要點
1 修改pom檔案
<build>
<plugins>
<!--這一步實作了光打自己的包-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<!--去除在生産環境中不變的依賴-->
<includes>
<include>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!--這裡的配置檔案裡寫了具體怎麼打包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-1</version>
<configuration>
<descriptor>src/main/resources/distribution/gs-spring-boot-distribution.xml</descriptor>
<finalName>gs-spring-boot-distribution</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- <resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources> -->
</build>
2 修改配置檔案
<assembly>
<formats>
<!--<format>tar</format>-->
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources/bin</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>start.sh</include>
<include>start.bat</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>config</outputDirectory>
<includes>
<include>*.properties</include>
<include>*.xml</include>
<include>env/dev/*</include>
<include>env/qa/*</include>
<include>env/uat/*</include>
<include>env/prod/*</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>logs</outputDirectory>
<fileMode>0755</fileMode>
<excludes>
<exclude>**/*</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
<!-- <unpack>false</unpack> -->
<excludes>
<!-- <exclude>${project.name}-${project.version}</exclude> -->
<exclude>${groupId}:${artifactId}</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
3 修改bat
-Dloader.path="../lib" -jar ../lib/gs-spring-boot-0.1.0.jar
4 代碼
https://github.com/chengzhaoan/gs-spring-boot-pkg