Springboot项目打瘦包(将依赖包放到jar包外)

一般springboot项目我们不做任何配置的话,打包会包含很多的依赖,生成的包过大,动辄100M以上,往生产环境上传很慢。所以把所有用的jar包打到外部,这样生成的小包中只有自已开发的程序,基本可以控制在1M以内,效果甚好。

首先把springboot自动生成的plugin删掉:

<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

然后添加以下内容:

<build><resources><!--打包时添加有用前端资源和配置文件,如resource下还有一些无关紧要的文件,该配置就可以尽量减小打包的jar的大小--><resource><directory>src/main/resources</directory><includes><include>static/</include><include>templates/</include><include>*.properties</include></includes><filtering>true</filtering></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><!--主类: 使用清单文件 --><manifest><addClasspath>true</addClasspath><mainClass>com.zhbr.gs_sparklauncher.GsSparkLauncherApplication</mainClass><classpathPrefix>lib/</classpathPrefix></manifest></archive></configuration></plugin><!-- 将依赖jar包统一拷贝到lib文件夹 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>copy</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin></plugins>
</build>
打包的效果:

在这里插入图片描述

项目部署:

config目录存放配置文件,lib目录存放依赖jar包。部署后的效果如下图所示:
在这里插入图片描述


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部