maven指定本地jar包


來自 https://blog.csdn.net/zhengxiangwen/article/details/50734565

一、怎么添加jar到本地倉庫呢?
步驟:
1.cmd命令進入該jar包所在路徑
2.執行命令:
mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar
其中:-DgroupId和-DartifactId的作用是指定了這個jar包在repository的安裝路徑,只是用來告訴項目去這個路徑下尋找這個名稱的jar包。
比如:
mvn install:install-file -Dfile=hadoop-hdfs-2.2.0.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -Dpackaging=jar
就是指把hadoop-hdfs-2.2.0.jar安裝到repository\org.apache.hadoop\hadoop-hdfs\2.2.0目錄下,執行完命令后,如果需要在項目中使用這個jar,則在pom.xml中添加如下配置即可:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.2.0</version>
</dependency>

注意在每個參數前有個-D

二、怎么在pom.xml中添加項目中libs下的jar呢,而不是從本地倉庫中添加?

1、首先將要添加的jar包復制到項目中的libs文件夾下

2、然后在pom.xml中添加如下代碼:

<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.21-OSGi</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/htmlunit-2.21-OSGi.jar</systemPath>
</dependency>

注意scope元素和systemPath元素,其中systemPath元素指定的就是jar包在項目中的路徑。

注意libs文件夾下的這個jar包不需要Add to Build Path
下面是maven中央倉庫的地址:http://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit/2.21

可以在這里搜索想要的jar包,然后復制對應的依賴代碼到你項目中的pom.xml中,則對應的jar包將下載到你本地的maven倉庫中,以提供給你使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM