给一个小Demo

<dependency>
<groupId>your.organization</groupId>
<artifactId>your-sdk-util</artifactId>
<version>1.1.1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/your-sdk-ver.jar</systemPath>
</dependency>

坐标可以任意给。${basedir}表示项目根目录。但打包时会出如下告警:

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.wo:AlarmReport:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.wo:taobao-sdk-java-auto:jar should not point at files within the project directory, ${basedir}/lib/taobao-sdk-java-auto.jar will be unresolvable by dependent projects @ line 61, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]

所以需要把${basedir}改为${pom.basedir}

<systemPath>${pom.basedir}/lib/your-sdk-ver.jar</systemPath>

这样来抑制上述告警。

pom.xml文件的打包插件要配置includeSystemScope属性,否则scope为system的依赖包不会被maven打包进项目,导致打包后的项目无法引用本地的第三方jar包。

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

也可以把jar包通过maven安装到本地(仓库)再引用

操作步骤如下:

  1. cmd命令进入该jar包所在路径。
  2. 执行如下语句:
mvn install:install-file -Dfile=bdl-service-1.0-SNAPSHOT.jar -DgroupId=com.baidu -DartifactId=bdl-service -Dversion=1.0-SNAPSHOT -Dpackaging=jar

语句说明:把bdl-service-1.0-SNAPSHOT.jar安装到repository\com\baidu\bdl-service\1.0-SNAPSHOT\目录下。

-Dfile :本地jar包名称。

-DgroupId :安装到repository的中路径

-DartifactId :安装到repository的中路径

-Dversion :用来指定包的版本号

-Dpackaging :打包形式

  1. pom.xml中引用坐标:
<dependency>
<groupId>com.baidu</groupId>
<artifactId>bdl-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>