maven中手動將jar包安裝進倉庫的方法及問題
阿新 • • 發佈:2017-08-08
maven
眾所周知,我們只要在pom.xml文件中進行配置,maven就會自動下載jar包到本地倉庫,那麽,如果我們自己寫一個jar包自己用,那麽便無法通過配置來引用這個包,需要我們手動將包安裝進倉庫中。
我們使用命令mvn install:install-file -Dfile=your-jar-file-path -DgroupId=com.your.group -DartifactId=your-artifactId -Dversion=x.x -Dpackaging=jar在doc中進行jar的安裝
-Dfile:指明需要安裝的jar包所在的位置
-DgroupId:指明groupId
-DartifactId:指明artifactId
-Dversion:指明版本
上面的後三個參數對應pom文件中配置時的三個參數,兩者要對應,pom文件中如下:
<dependency> <groupId>alipay</groupId> <artifactId>alipay</artifactId> <version>1.0.0</version> </dependency>
當我們執行這個命令時切記要在pom文件所在的路徑下,否則會報如下錯誤(找不到pom文件):
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- [ERROR] The specified file ‘C:\Users\user\your-jar-file-path‘ not exists [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.363 s [INFO] Finished at: 2017-08-07T21:09:17+08:00 [INFO] Final Memory: 6M/63M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project standalone-pom: The specified file ‘C:\Users\user\your-jar-file-path‘ not exists -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
當我們進入pom文件路徑下執行便會執行成功:
[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.ai.ecs:ics-web:war:0.0.1 [WARNING] ‘build.plugins.plugin.(groupId:artifactId)‘ must be unique but found duplicate declaration of plugin org.mortbay.jetty:jetty-maven-plugin @ com.ai.ecs:ics-web:[unknown-version], C:\yx\nanjingSvn(1)\src\echannel\trunk\web\ics-web\pom.xml, line 204, column 13 [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] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ics-web 0.0.1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ ics-web --- [INFO] Installing D:\my-jar\alipay-sdk-java20170307171631.jar to C:\Users\user\m2\repository\com\your\group\your-artifactId\0.0.0\your-artifactId-0.0.0.jar [INFO] Installing C:\Users\user\AppData\Local\Temp\mvninstall959507239612006886.pom to C:\Users\user\m2\repository\com\your\group\your-artifactId\0.0.0\your-artifactId-0.0.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.396 s [INFO] Finished at: 2017-08-07T21:12:48+08:00 [INFO] Final Memory: 9M/108M [INFO] ------------------------------------------------------------------------
安裝完之後我們打開本地倉庫就會看到創建出了自己所加的文件路徑,然後我們在pom文件中添加依賴就ok了
maven中手動將jar包安裝進倉庫的方法及問題