向Maven的本地庫中添加jar檔案,maven添加jar

來源:互聯網
上載者:User

向Maven的本地庫中添加jar檔案,maven添加jar

有時我們要用的 maven 依賴項在官方repo庫中找不到,然而我們從其他渠道獲得了依賴項中的所有jar檔案,本文記錄了如何向本地庫添加jar檔案。

從複雜到簡單,有三種方法:

第一種方法有利於團隊開發,內容多一點,我打算單獨用一篇文章記錄。這裡介紹其他兩種方法:

 

使用指令 mvn install:install-file 將jar檔案安裝到本地倉庫

文法規範:

mvn install:install-file    -Dfile=<path-to-file>    -DgroupId=<group-id>    -DartifactId=<artifact-id>    -Dversion=<version>    -Dpackaging=<packaging>    -DgeneratePom=true    Where: <path-to-file>  the path to the file to load         <group-id>      the group that the file should be registered under         <artifact-id>   the artifact name for the file         <version>       the version of the file         <packaging>     the packaging of the file e.g. jar

我們以檔案<not-yet-commons-ssl-0.3.17.jar>為例:

mvn install:install-file  -Dfile=e:\not-yet-commons-ssl-0.3.17.jar  -DgroupId=org.apache.commons  -DartifactId=not-yet-commons-ssl  -Dversion=0.3.17  -Dpackaging=jar  -DgeneratePom=true

 

通過項目pom設定檔引入

編輯項目pom檔案,在依賴項中增加條目,並指定<scope>和<systemPath>。

還是以檔案<not-yet-commons-ssl-0.3.17.jar>為例:

<dependency>    <groupId>org.apache.commons</groupId>    <artifactId>not-yet-commons-ssl</artifactId>    <version>0.3.17</version>    <scope>system</scope>    <systemPath>e:\not-yet-commons-ssl-0.3.17.jar</systemPath></dependency>

等等,編譯後出現一個警告:

[WARNING] 'dependencies.dependency.systemPath' for org.apache.commons:not-yet-commons-ssl:jar should use a variable instead of a hard-coded path e:\not-yet-commons-ssl-0.3.17.jar @ line 35, 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.

原來是 maven 苦口婆心地告訴我們不要使用諸如 C:\Windows 這樣的絕對路徑,而應使用 ${java.home} 這樣的相對路徑(變數),否則降低了編譯可重現性,並威脅我們以後可能不再支援這種方式。

嗯,我們可以建立一個 maven 倉庫的環境變數來消除這個警告,如果你覺得有這個必要。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.