腦洞的由來
場景一:微服務部署,每個微服的包體都幾十M,而且每個微服包體之間都有大量重復jar包
功能需求
比如當前項目是lp-spring-web,打包出來的包體是lp-spring-web.jar
- lp-spring-web.jar 只包含項目的字節(jié)碼文件,也就只有class文件,而沒有l(wèi)ib文件
- lp-sping-web項目依賴的jar包需要一份完整copy在lp-spring-web.jar外
Git地址
https://gitee.com/wqrzsy/lp-demo/tree/master/lp-spring-web
更多demo請關注
springboot demo實戰(zhàn)項目
java 腦洞
java 面試寶典
開源工具
功能實現
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>non-exists</groupId>
<artifactId>non-exists</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>classes</classifier>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
執(zhí)行 mvn package 后

image.png

image.png
我們打開lib文件夾就會看到相關依賴的jar包都在里面

image.png
測試
我們寫一個bat來測試下是否成功
java -jar -Dloader.path=./target,./target/lib ./target/lp-spring-web-0.0.1-SNAPSHOT.jar
PS: 路徑可自行修改

image.png
運行run.bat 后就會看到項目已正常啟動

image.png
demo項目導入
參考: http://www.itdecent.cn/p/cd0275a2f5fb
公眾號
五分鐘了解前沿技術,大數據,微服務,區(qū)域鏈,提供java前沿技術干貨,獨立游戲制作技術分享

五分鐘技術
如果這篇文章對你有幫助請給個star

image.png