Maven

添加第三方Jar

指令

安装指定文件到本地仓库命令:mvn install:install-file
-DgroupId= : 设置项目代码的包名(一般用组织名)
-DartifactId= : 设置项目名或模块名
-Dversion=1.0.0 : 版本号
-Dpackaging=jar : 什么类型的文件(jar包)
-Dfile=<myfile.jar> : 指定jar文件路径与文件名,同目录只需文件名。

实战

  1. 打开本地CMD终端,运行命令
    mvn install:install-file -DgroupId=com.alibaba -DartifactId=http-sdk-plus -Dversion=1.0.4.2 -Dpackaging=jar -Dfile=http-sdk-1.0.4.2plus.jar
    
    运行结果
    [INFO] Scanning for projects...
    [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 ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.294 s
    [INFO] Finished at: 2019-11-07T13:41:58+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project standalone-pom: The artifact information is incomplete or not valid:
    [ERROR]   [0]  'packaging' is missing.
    [ERROR]
    [ERROR] -> [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/MojoExecutionException
    
    

发现执行失败,根据提示***[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project standalone-pom: The artifact information is incomplete or not valid*** ,发现执行该命令所在路径不对,应切入到需要引入该jar包所在工程的pom路径下再执行。

  1. 切换至目标工程pom所在路径,然后重新执行指令

    E:\目标工程所在路径>mvn install:install-file -DgroupId=com.alibaba -DartifactId=http-sdk -Dversion=1.0.4.2plus -Dpacking=jar -Dfile=E:\xxx\xxx\http-sdk-1.0.4.2plus.jar
    [INFO] Scanning for projects...
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.pom (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.jar
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.0.0/maven-clean-plugin-3.0.0.jar (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.pom (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.pom (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.jar
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.jar (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.21.0/maven-surefire-plugin-2.21.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.21.0/maven-surefire-plugin-2.21.0.pom (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.21.0/surefire-2.21.0.pom
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.21.0/surefire-2.21.0.pom (0 B at 0 B/s)
    Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.21.0/maven-surefire-plugin-2.21.0.jar
    Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.21.0/maven-surefire-plugin-2.21.0.jar (0 B at 0 B/s)
    [INFO]
    [INFO] -------------< com.1012china:single-purpose-prepaid-card >--------------
    [INFO] Building single-purpose-prepaid-card 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-install-plugin:2.5.2:install-file (default-cli) @ single-purpose-prepaid-card ---
    [INFO] Installing E:\xxx\http-sdk-1.0.4.2plus.jar to C:\Users\chenglong.dong\.m2\repository\com\alibaba\http-sdk\1.0.4.2plus\http-sdk-1.0.4.2plus.jar
    [INFO] Installing C:\Users\xxx\AppData\Local\Temp\mvninstall4751014964381397731.pom to C:\Users\xxx\.m2\repository\com\alibaba\http-sdk\1.0.4.2plus\http-sdk-1.0.4.2plus.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.707 s
    [INFO] Finished at: 2019-11-07T13:43:38+08:00
    [INFO] ------------------------------------------------------------------------
    
  2. 导入成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值