前言

最近在做项目时,需要用到外部包,因为这个包不能通过Maven引入,只能本地引入。借鉴他人方法,结合项目实际情况进行修改,并做记录,以备用。

引入本地jar包

在 pom.xml 文件中的 dependencies 标签下添加如下代码:

  1. <dependency>
  2. <groupId>org.jeecgframework.boot</groupId>
  3. <artifactId>jeecg-system-local-api</artifactId>
  4. <version>3.0</version>
  5. <scope>system</scope>
  6. <systemPath>/Users/lxy/Documents/libs/jeecg-system-local-api-3.0.jar</systemPath>
  7. </dependency>

systemPath 标签表示本地jar包绝对路径。

你也可以放在项目根目录下的 libs 目录下,例如:

  1. <dependency>
  2. <groupId>org.jeecgframework.boot</groupId>
  3. <artifactId>jeecg-system-local-api</artifactId>
  4. <version>3.0</version>
  5. <scope>system</scope>
  6. <systemPath>${project.basedir}/libs/jeecg-system-local-api-3.0.jar</systemPath>
  7. </dependency>

${project.basedir} 表示项目根目录。

scope几个选项说明:

  • compile:默认的scope,运行期有效,需要打入包中
  • provided:编译期有效,运行期不需要提供,不会打入包中
  • runtime:编译不需要,在运行期有效,需要导入包中
  • test:测试需要,不会打入包中
  • system:非本地仓库引入、存在系统的某个路径下的jar

打包时添加本地jar包

在 pom.xml 文件中的 build ➡plugins 标签下添加如下代码:

  1. <plugin>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-maven-plugin</artifactId>
  4. <configuration>
  5. <!--打包时允许添加本地jar包-->
  6. <includeSystemScope>true</includeSystemScope>
  7. </configuration>
  8. </plugin>