前言
最近在做项目时,需要用到外部包,因为这个包不能通过Maven引入,只能本地引入。借鉴他人方法,结合项目实际情况进行修改,并做记录,以备用。
引入本地jar包
在 pom.xml 文件中的 dependencies 标签下添加如下代码:
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-local-api</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>/Users/lxy/Documents/libs/jeecg-system-local-api-3.0.jar</systemPath>
</dependency>
systemPath 标签表示本地jar包绝对路径。
你也可以放在项目根目录下的 libs 目录下,例如:
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-local-api</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/jeecg-system-local-api-3.0.jar</systemPath>
</dependency>
${project.basedir} 表示项目根目录。
scope几个选项说明:
- compile:默认的scope,运行期有效,需要打入包中
- provided:编译期有效,运行期不需要提供,不会打入包中
- runtime:编译不需要,在运行期有效,需要导入包中
- test:测试需要,不会打入包中
- system:非本地仓库引入、存在系统的某个路径下的jar
打包时添加本地jar包
在 pom.xml 文件中的 build ➡plugins 标签下添加如下代码:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--打包时允许添加本地jar包-->
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>