spring boot引入并打包外部jar包的记录

博客介绍了Spring Boot引入并打包外部jar包的方法。首先在/src/main/resources下创建lib文件夹加入引入的包,然后在pom.xml中进行相应配置。

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

spring boot引入并打包外部jar包

1.引入jar包

在/src/main/resources下创建lib文件夹,加入引入的包

<dependency>
		<groupId>com.jd</groupId>
		<artifactId>sdk</artifactId>
		<version>2.0</version>
		<systemPath>${project.basedir}/src/main/resources/lib/sdk.jar</systemPath>
		<scope>system</scope>
	</dependency>

2. pom.xml 加上

<includeSystemScope>true</includeSystemScope>

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<includeSystemScope>true</includeSystemScope>
					<classifier>exec</classifier>
				</configuration>
			</plugin>
		</plugins>
	</build>
要将外部Jar引入Spring Boot项目中打包Jar中,可以按照以下步骤进行操作: 1. 在pom.xml文件中添加依赖项。例如,要引入一个名为example.jar外部Jar,可以通过以下方式添加依赖项: ``` <dependency> <groupId>com.example</groupId> <artifactId>example</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/example.jar</systemPath> </dependency> ``` 其中,systemPath指定了外部Jar的路径,scope设置为system,表示使用系统路径下的Jar。 2. 将外部Jar复制到项目的lib目录下,例如,将example.jar复制到项目目录下的lib文件夹中。 3. 在pom.xml文件中添加Maven插件,以将外部Jar打包到生成的Jar中。例如,可以添加以下插件: ``` <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.example.Application</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> ``` 其中,classpathPrefix指定了Jar中lib文件夹下的依赖项路径前缀,mainClass指定了Spring Boot应用程序的主。 4. 使用Maven命令进行打包,生成的Jar中将外部Jar。例如,使用以下命令进行打包: ``` mvn clean package ``` 这样,生成的Jar中就含了外部Jar可以在运行时使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值