給一個小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安裝到本地(倉庫)再引用
操作步驟如下:
- cmd指令進入該jar包所在路徑。
- 執行如下語句:
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的中路徑
- pom.xml中引用坐标:
<dependency>
<groupId>com.baidu</groupId>
<artifactId>bdl-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>