Springboot 打jar包分离lib,配置文件正确方式

本文详细介绍了如何使用Maven进行项目打包时排除特定模块和资源文件的方法。通过配置pom.xml中的maven-dependency-plugin和spring-boot-maven-plugin插件,实现项目依赖的第三方包的分离,并排除不需要被打包的模块。同时,通过调整resources标签,实现了对src/main/resources下指定文件的排除,确保这些文件可以外置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:https://my.oschina.net/xiaozhutefannao/blog/1932764

如只想jar分离可参考另一篇文档:https://blog.youkuaiyun.com/m0_37598340/article/details/86149186

参考文档处理时,一直出问题,稍微调整了一下出来了,我这个办法有点笨,模块较多的话会比较麻烦。

这边只列出调整了地方的配置文件

启动模块的pom.xml

<build>
		
		<plugins>
			<!-- 打出项目依赖的第三方包,放在lib下面(**相当于拷贝项目的jar包**) -->
			<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>
					<excludes>
						<!--  项目中的模块配置 ,可添加多个-->
						<exclude>
							<groupId>xxxxxx</groupId>
							<artifactId>aaaaaa</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
		</plugins>
		<!-- resources 排除了我们需要外置的文件(配置文件可以全部排除) -->
		<resources>
			<resource>
				<filtering>true</filtering>
				<directory>src/main/resources</directory>
				<excludes>
					<exclude>static/**</exclude>
					<exclude>templates/**</exclude>
					<exclude>*.yml</exclude>
					<exclude>*.properties</exclude>
					<exclude>*.xml</exclude>
					<exclude>*.txt</exclude>
					<exclude>dev_form_rule/**</exclude>
				</excludes>
			</resource>
		</resources>
	</build>

将target下lib包和test.jar(运行包)以及src/main/resources下你需要外置的文件部署至服务器同一目录下,如
在这里插入图片描述

启动时进入到启动jar的目录执行一下的命令

java -jar -Dloader.path=.,lib test.jar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值