spring boot源码和lib分开打包

1.项目通过maven引入的jar多了之后,用maven打出的jar会非常庞大,我的是因为引入了ffmpeg的相关jar,所以,每次上传服务更新都要传输好久,修改maven打包方式,改为源码和lib分离模式

2.maven的pom.xml配置如下

xml 复制代码
<build>
		<plugins>

			<!-- Step 1: 只打包源码(不包含依赖) -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>3.4.0</version>
				<configuration>
					<archive>
						<manifest>
							<mainClass>com.xxx.springboot.xxxxxApplication</mainClass> <!-- 替换为你自己的主类 -->
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
						</manifest>
						<manifestEntries>
						<!-- 不上maven管理的jar引入方式 -->
							<Class-Path>lib/DmJdbcDriver18-1.0.jar lib/encrypt-body-spring-boot-starter-1.2.3.jar</Class-Path>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>

			<!-- Step 2: 使用 spring-boot-maven-plugin 打包并提取依赖到 lib/ -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>repackage</id>
						<goals>
							<goal>repackage</goal>
						</goals>
						<configuration>
							<skip>true</skip> <!-- 禁用默认 repackage -->
						</configuration>
					</execution>
					<execution>
						<id>build-info</id>
						<goals>
							<goal>build-info</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<!-- Step 3: 提取依赖到 target/lib/ -->
			<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>${project.build.directory}/lib</outputDirectory>
							<overWriteReleases>false</overWriteReleases>
							<overWriteSnapshots>false</overWriteSnapshots>
							<overWriteIfNewer>true</overWriteIfNewer>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- Step 4 (可选): 创建最终发布的 dist 文件夹 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<mkdir dir="${project.build.directory}/dist"/>
								<copy file="${project.build.directory}/${project.build.finalName}.jar"
									  tofile="${project.build.directory}/dist/chenzhou.jar"/>
								<copy todir="${project.build.directory}/dist/lib">
									<fileset dir="${project.build.directory}/lib"/>
								</copy>
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>

3.对于非maven仓库中的包处理方式

xml 复制代码
<!-- 非maven仓库包 -->
<dependency>
	<groupId>com-dm</groupId>
	<artifactId>DmJdbcDriver18</artifactId>
	<version>1.0</version>
	<scope>system</scope>
	<systemPath>${project.basedir}/lib/DmJdbcDriver18.jar</systemPath>
</dependency>
<!-- 指定jar位置,多个以空格分开,对于不上版本结尾的名称,打包放入lib后会自动增加1.0,所以,引入jar写入也要增加 
例如:达梦数据库驱动包,项目实际引入DmJdbcDriver18.jar
在Class-Path中的配置要为:DmJdbcDriver18-1.0.jar
-->
<manifestEntries>
	<Class-Path>lib/DmDialect-for-hibernate6.1-1.0.jar lib/DmJdbcDriver18-1.0.jar</Class-Path>
</manifestEntries>

如有不妥之处,请谅解!

相关推荐
愿你天黑有灯下雨有伞23 分钟前
告别复杂配置!Spring Boot优雅集成百度OCR的终极方案
spring boot·百度·ocr
武子康4 小时前
Java-80 深入浅出 RPC Dubbo 动态服务降级:从雪崩防护到配置中心秒级生效
java·分布式·后端·spring·微服务·rpc·dubbo
舒一笑5 小时前
我的开源项目-PandaCoder迎来史诗级大更新啦
后端·程序员·intellij idea
@昵称不存在6 小时前
Flask input 和datalist结合
后端·python·flask
zhuyasen6 小时前
Go 分布式任务和定时任务太难?sasynq 让异步任务从未如此简单
后端·go
东林牧之7 小时前
Django+celery异步:拿来即用,可移植性高
后端·python·django
超浪的晨8 小时前
Java UDP 通信详解:从基础到实战,彻底掌握无连接网络编程
java·开发语言·后端·学习·个人开发
AntBlack8 小时前
从小不学好 ,影刀 + ddddocr 实现图片验证码认证自动化
后端·python·计算机视觉
Pomelo_刘金8 小时前
Clean Architecture 整洁架构:借一只闹钟讲明白「整洁架构」的来龙去脉
后端·架构·rust
双力臂4048 小时前
Spring Boot 单元测试进阶:JUnit5 + Mock测试与切片测试实战及覆盖率报告生成
java·spring boot·后端·单元测试