maven仓库手动安装本地jar经典方法以及遇到的问题解决方法

  1. 介绍
    在java开发过程中,经常会遇到一些包在maven仓库中无法下载的问题,如ojdbc,saxon等等,因此需要手动将本地jar包安装到maven仓库,来解决pom依赖的问题。
  2. 方法
    ** maven添加本地包命令mvn install:install-file **

maven本地安装 xml2j

mvn install:install-file -Dfile=xml2j.jar -DgroupId=com.xml2j -DartifactId=xml2j-core -Dversion=2.5.0 -Dpackaging=jar

mvn install:install-file 标识通过文件方式安装
-Dfile 指定要上传的jar包
-DgroupId 制定包名
-DartifactId 制定上传后的jar项目名称
-Dversion 制定仓库中的版本号
-Dpackaging 打包方式
  1. 问题与解决方法
    ** 3.1 本地打包遇到目录无效(windows powershell)**

报错信息:

PS E:\大数据\002.项目材料\003.爱建信托·风控系统\009.研发交付\002.道琼斯指数> mvn install:install-file -Dfile=xml2j.jar -DgroupId=com.xml2j -DartifactId=xml2j-core -Dversion=2.5.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.126 s
[INFO] Finished at: 2019-06-02T09:54:36+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (E:\大数据\002.项目材料\003.爱建信托·风控系统\009.研发交付\002.道琼斯指数). 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

解决办法:

通常是由于无法找到对应目录导致,需采用cmd进行打包,具体步骤如下:
# 切换盘符
e:
# 切换目录
cd E:\大数据\002.项目材料\003.爱建信托·风控系统\009.研发交付\002.道琼斯指数
# 打包
mvn install:install-file -Dfile=xml2j.jar -DgroupId=com.xml2j -DartifactId=xml2j-core -Dversion=2.5.0 -Dpackaging=jar
# 打包成功
E:\大数据\002.项目材料\003.爱建信托·风控系统\009.研发交付\002.道琼斯指数>mvn install:install-file -Dfile=saxon.jar -DgroupId=com.icl.saxon -DartifactId=saxon -Dversion=6.5.5 -Dpackaging=jar
[INFO] Scanning for projects...
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (6.4 kB at 5.5 kB/s)
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (2.5 kB at 8.7 kB/s)
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar
Downloaded from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (230 kB at 384 kB/s)
[INFO] Installing E:\大数据\002.项目材料\003.爱建信托·风控系统\009.研发交付\002.道琼斯指数\saxon.jar to C:\Users\troll\.m2\repository\com\icl\saxon\saxon\6.5.5\saxon-6.5.5.jar
[INFO] Installing C:\Users\troll\AppData\Local\Temp\mvninstall4944592553766850504.pom to C:\Users\troll\.m2\repository\com\icl\saxon\saxon\6.5.5\saxon-6.5.5.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.828 s
[INFO] Finished at: 2019-06-02T09:40:11+08:00
[INFO] ------------------------------------------------------------------------

通常本地jar包上传maven仓库比较顺利,目前仅遇到此问题,如果大家有遇到不同的问题,欢迎在评论区留言,以便相互学习和处理,谢谢

你可能感兴趣的:(java,maven)