springboot 引入外部jar包 并使用maven打包成jar文件

最近有一个小需求,在开发的过程中,需要引入外部jar包,然后用maven进行打包部署. 查阅了一些资料,决定把它记录下来.

  • 首先在项目根目录创建一个 lib 文件夹
    在这里插入图片描述
  • 然后在把外部的jar包放入lib文件夹中,
    在这里插入图片描述
  • 在pom.xml中加入这些依赖
	<dependency>
			<groupId>org.apache.poi</groupId>  <!--自定义-->
			<artifactId>scratchpad</artifactId>    <!--自定义-->
			<version>1.0</version> <!--自定义-->
			<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
			<systemPath>${basedir}/lib/poi-scratchpad-3.17.jar</systemPath> <!--项目根目录下的lib文件夹下-->
		</dependency>
------------------------------------------------------------------------------------------------------------------------------------
<!--最重要的一步 -->
<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<!--引入外部jar包 并配置  无此项外部jar打包时无法引入包中  -->
					<includeSystemScope>true</includeSystemScope>
				</configuration>
			</plugin>
		</plugins>
	</build>

参考博文:
https://blog.csdn.net/weixin_37264997/article/details/80370766

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要将外部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
发出的红包

打赏作者

漫长的~以后

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值