java spring boot maven 引入第三方jar包 以及scope配置

首先 项目根目录下(与src等平行目录)创建文件夹 lib 然后将你所需要用的jar包放在该文件夹下 如图所示

然后pom中引入你新加的jar包

<dependency>
			<groupId>*****</groupId>
			<artifactId>***</artifactId>
			<version>2.0</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/lib/***.jar</systemPath>
</dependency>

关于scope

  • compile 默认的scope
  • 表示 dependency 可以在生命周期中使用。而且这些dependencies 会传递到依赖的项目中。
  • provided
  • 跟compile相似,但是表明了dependency 由JDK或者容器提供。
    例如Servlet AP和一些Java EE APIs。这个scope 只能作用在编译和测试时,同时没有传递性。
    使用这个时,不会将包打入本项目中,只是依赖过来。(when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.)
  • runtime
  • 表示dependency不作用在编译时,但会作用在运行和测试时
  • test
  • 表示dependency作用在测试时,不作用在运行时
  • system
  • 跟provided 相似,但是在系统中要以外部JAR包的形式提供,maven不会在repository查找它。 

 

  • import (Maven 2.0.9 之后新增)
  • 它只使用在<dependencyManagement>中,表示从其它的pom中导入dependency的配置,例如 (B项目导入A项目中的包配置):

依赖引入之后 你本地就可以使用了 但是要想将其打到项目的jar包里 还需要如下配置

pom  build节点下新增

<resources>  
     <resource>  
         <directory>lib</directory>  
         <targetPath>BOOT-INF/lib/</targetPath>  
         <includes>  
             <include>**/*.jar</include>  
         </includes>  
     </resource>
 </resources>

以及

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

看是否成功 检查你的target目录下是否出现了 lib/***.jar文件

如上配置之后第三方jar包就可以正常使用了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值