本地jar包在maven工程中pom引用



背景

  在使用Maven的過程中,經常碰到有些jar包在中央倉庫沒有的情況。如果公司有私服,那么就把jar包安裝到私服上。如果沒有私服,那就把jar包安裝到本地Maven倉庫。下面是如何把jar包導入本地maven倉庫。


解決方法

1、確定包信息

groupId:設置項目代碼的包名(一般用公司或組織名)
artifactId:設置項目名或模塊名 
version:版本號
packaging:什么類型的文件(jar包)
filePath:指定jar文件路徑與文件名(同目錄只需文件名)

2、在工程根目錄下執行如下maven命令:

mvn install:install-file -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=jar -Dfile=<filePath>

3、在pom的包依賴中引入剛才

<dependency>  
  <!--if add it into the </dependencyManagement>, it does not work-->  
  <groupId>[groupId]</groupId>  
  <artifactId>[artifactId]</artifactId>  
  <version>[version]</version>  
  <systemPath>[filePath]</systemPath>
  <scope>system</scope>
</dependency>

注意:maven命令在window系統下,不能使用powershell,否則會包xxx not exits。



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM