比如我下載了
一、怎么添加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>
PS:不執行命令、通過手動在本地倉庫創建文件夾的方式也是可以的,此時如果pom報錯,可以在maven-》update project時勾選 force update of snapshots/releases 選項即可
二、怎么在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
注意通過這種方式引入的jar包在打包時不會被包含在war包中