maven引入本地jar包的三种方式

有些jar包并非可以从在线仓库中下载到的,还有些是自己写的jar包要给其他人用,使用这样的一些jar包总结了3中方式:

方式一:
使用scope 为 system 引入本地jar
不太推荐使用这种方式。
将jar包复制到项目的lib目录中,然后在pom中这样引用:

<dependency>
    <groupId>随便写</groupId>
    <artifactId>随便写</artifactId>
    <version>随便写</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/xxxxxxx.jar</systemPath>
</dependency>

b a s e d i r 不 用 改 , 就 这 么 写 , 你 只 用 把 x x x x x x 换 成 你 的 j a r 名 称 就 可 以 了 , {basedir}不用改,就这么写,你只用把xxxxxx换成你的jar名称就可以了, basedirxxxxxxjar{basedir}应该是maven提供的一个变量,代表项目的根目录;

groupId、artifactId、version 这三个不能省略,但可以随便写;

方式二:
有时候我们直接将jar放到本地仓库对应的文件夹中,然后在eclipse里面在项目上右键–>Maven->Update Project… 也行,但有时候又不行,报错提示下载那个jar文件的 xx.pom 失败,所以最好是使用这种方式安装到本地仓库,会自动创建一个xx.pom的文件:
使用maven 命令 将jar包安装到自己的本地仓库,然后在pom中引用,

mvn install:install-file -Dfile=D:/xxxxxx.jar -DgroupId=自定义groupId -DartifactId=自定义artifactId -Dversion=自定义version  -Dpackaging=jar

在pom中就可以这样引用

<dependency>
    <groupId>自定义groupId</groupId>
    <artifactId>自定义artifactId</artifactId>
    <version>自定义version</version>
</dependency>

方式三:
使用maven 命令 将jar包上传到自己搭建的私服中,然后在pom中引用
如何搭建私服、在maven的配置文件中配置自己的私服就不说了,很多文章讲这个。
上传jar包到私服的命令:

mvn deploy:deploy-file -DgroupId=自定义groupId -DartifactId=自定义artifactId -Dversion=自定义version -Dpackaging=jar -Dfile=D:/xxxxxx.jar -Durl=http://私服地址/repository/maven-3rd/ -DrepositoryId=maven-3rd 

在pom中就可以这样引用

<dependency>
    <groupId>自定义groupId</groupId>
    <artifactId>自定义artifactId</artifactId>
    <version>自定义version</version>
</dependency>

我一般使用第三种方式

  • 4
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值