maven指定本地jar包

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

1、怎麼添加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>apache

注意在每一個參數前有個-Dmaven

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

一、首先將要添加的jar包複製到項目中的libs文件夾下ui

二、而後在pom.xml中添加以下代碼:.net

<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>xml

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

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

能夠在這裏搜索想要的jar包,而後複製對應的依賴代碼到你項目中的pom.xml中,則對應的jar包將下載到你本地的maven倉庫中,以提供給你使用。hadoop