如何在maven的pom.xml中添加本地jar包

如何在maven的pom.xml中添加本地jar包,第1张

步骤:
1cmd命令进入该jar包所在路径
2执行命令:
mvn install:install-file -Dfile=lucene-queryparser-461jar
-DgroupId=orgapachelucene -DartifactId=lucene-queryparser
-Dversion=461 -Dpackaging=jar
其中:-DgroupId和-DartifactId的作用是指定了这个jar包在repository的安装路径,只是用来告诉项目去这个路径下寻找这个名称的jar包。
比如:
mvn install:install-file -Dfile=hadoop-hdfs-220jar
-DgroupId=orgapachehadoop -DartifactId=hadoop-hdfs -Dversion=220 -D
-Dpackaging=jar
就是指把hadoop-hdfs-220jar安装到repository\orgapachehadoop\hadoop-hdfs\220目录下,执行完命令后,如果需要在项目中使用这个jar,则在pomxml中添加如下配置即可:
<dependency>
<groupId>orgapachehadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>220</version>
</dependency>
注意在每个参数前有个-D
二、怎么在pomxml中添加项目中libs下的jar呢,而不是从本地仓库中添加?
1、首先将要添加的jar包复制到项目中的libs文件夹下
2、然后在pomxml中添加如下代码:
[html] view plain copy
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>221-OSGi</version>
<scope>system</scope>
<systemPath>${projectbasedir}/libs/htmlunit-221-OSGijar</systemPath>
</dependency>
注意scope元素和systemPath元素,其中systemPath元素指定的就是jar包在项目中的路径。
注意libs文件夹下的这个jar包不需要Add to Build Path


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13388345.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-26
下一篇 2023-07-26

发表评论

登录后才能评论

评论列表(0条)

保存