【125】Maven安裝本地jar包
阿新 • • 發佈:2018-12-14
實際開發中,雖然大多數的jar包都可以使用maven管理,但是總會遇到一些特殊的jar包沒有儲存到maven庫中。此時就需要我們學會如何用maven安裝本地jar包。本文以 java-sdk-core-2.0.1.jar 檔案為例,講一下maven如何安裝本地jar包。
第一步,命令列進入jar包所在的目錄。執行如下命令:
mvn install:install-file -Dfile=java-sdk-core-2.0.1.jar -DgroupId=com.huawei.apigateway -DartifactId=java-sdk-core -Dversion=2.0.1 -Dpackaging=jar
第二步,專案裡面直接配置依賴
<dependency>
<groupId>com.huawei.apigateway</groupId>
<artifactId>java-sdk-core</artifactId>
<version>2.0.1</version>
</dependency>
這裡注意一下,命令列裡面的 DgroupId 選項對應配置檔案中的 groupId;命令列裡面的 DartifactId 選項對應配置檔案的 artifactId;命令列裡面的 Dversion 選項對應配置檔案的 version。
第三步,更新專案,並重新編譯專案。可以執行 mvn clean compile
命令重新編譯整個專案。