向maven本地仓库手动导入jar包
步骤
-
将jar包放在指定位置 。路径中不要有空格,有空格的话会报错
Windows路径 C:\Users\DossS\Desktop Linux路径 $HOME/Downloads/messageUtil/touch-sms-api.jar
- 打开cmd,输入如下命令
Windows命令: mvn install:install-file -Dfile=C:\Users\DossS\Desktop\touch-sms-api.jar // jar包路径 -DgroupId=com.wondersgroup.frame.common.touch-sms-api -DartifactId=touch-sms-api -Dversion=1.0 -DgeneratePom=true -Dpackaging=jar Linux命令: mvn install:install-file -Dfile=$HOME/Downloads/messageUtil/touch-sms-api.jar // jar包路径 -DgroupId=com.wondersgroup.frame.common.touch-sms-api -DartifactId=touch-sms-api -Dversion=1.0 -DgeneratePom=true -Dpackaging=jar
- 在maven项目的pom.xml中添加对应依赖
<dependency> <groupId>com.wondersgroup.frame.common.touch-sms-api</groupId> <artifactId>touch-sms-api</artifactId> <version>1.0</version> </dependency>
坑
- Windows下最好将jar包放在c盘目录下,否则可能报错,如下图所示。
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.154 s [INFO] Finished at: 2018-09-10T13:16:13+08:00 [INFO] Final Memory: 7M/245M [INFO] ------------------------------------------------------------------------ [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\DossS). Please verify you invoked Maven from the correct directory. -> [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/MissingProjectException
- 注意maven settings.xml配置的localRepository路径,因为idea可以使用其他路径下的仓库,因此可能找不到指定的仓库
- 手动输入的命令参数要全
参考文献
操作步骤
https://blog.csdn.net/qq_36745087/article/details/79229191
https://blog.csdn.net/u012898245/article/details/79210635
报错原因
https://bbs.csdn.net/topics/390776321
https://stackoverflow.com/questions/21497607/install-maven-jar-with-pom-into-local-repository
http://maven.apache.org/plugins/maven-install-plugin/examples/custom-pom-installation.html