如何引入本地jar包到Maven中?

183 阅读1分钟

有时候,需要引⼊在中央仓库找不到的 jar,但⼜想通过 maven 进⾏管理,那么应该如何做到呢?

可以通过设置 dependency 的 scope 为 system 来引⼊本地 jar

  • 将私有 jar 放置在 resouces/lib 下,然后以如下⽅式添加依赖:

  • groupId 和 artifactId 可以按照 jar 包中的 package 设置,只要和其他 jar 不冲突即可。

<dependency>
  <groupId>xxx</groupId>
  <artifactId>xxx</artifactId>
  <version>1.0.0</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/src/main/resources/lib/xxx-6.0.0.jar</systemPath>
</dependency>