首页 > 代码库 > maven中手动将jar包安装进仓库的方法及问题
maven中手动将jar包安装进仓库的方法及问题
众所周知,我们只要在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包安装进仓库的方法及问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。