将本地jar添加到Maven仓库,使用pom.xml引用

一、将jar添加到本地仓库的做法:

以下面pom.xml依赖的jar包为例:

实际项目中pom.xml依赖写法:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.1.0.RELEASE</version>
</dependency>

打开你的cmd,输入一下命令,Maven 安装 JAR 包的命令是:

mvn install:install-file  -Dfile=jar包的位置  -DgroupId=上面的groupId  -DartifactId=上面的artifactId  -Dversion=上面的version  -Dpackaging=jar
例如我的这个spring-context-support-3.1.0.RELEASE.jar 文件放在了"D:\mvn\"中

则命令为:

mvn install:install-file 
-Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar 

-DgroupId=org.springframework 

-DartifactId=spring-context-support 

-Dversion=3.1.0.RELEASE 

-Dpackaging=jar

注意:

  • 任何路径和名称不要有中文和空格,以防出现莫名其妙的错误。
  • 在cmd窗口输入命令,所有命令不要回车换行,最好在文本中缩进为一行再复制过去运行

还可以解决本地仓库是从别人那边复制的,但是需要的jar包中央仓库不存在,导致的执行package时出现以下异常

Failed to execute goal on project relayserver: Could not resolve dependencies for project com.xxx:xxx:war:1.0-SNAPSHOT: Failure to find xxx.xxx:xxx:jar:1.0 in http://maven.aliyun
.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus-aliyun has elapsed or updates are forced 

二、不讲jar包添加到本地仓库也可在maven工程中使用外部jar包的做法:


假设将包htmlparser.jar放入了项目下的lib目录中 :

-> ${project}/lib/htmlparser.jar
则pom.xml文件中依赖可以如下:
<dependency>
    <groupId>com.htmlparser</groupId>
    <artifactId>htmlparser</artifactId>
    <version>2.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/htmlparser.jar</systemPath>
</dependency>

--------------------- 
作者:哈利路亚--Java 
来源:CSDN 
原文:https://blog.csdn.net/a491857321/article/details/51085167 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值