問題:
從 pom.xml 文件中直接寫依賴下載不到的jar文件,先手動下載到本地后如何添加到本地倉庫
方法:
- 將下載到本地的JAR包手動添加到Maven倉庫
常用Maven倉庫網(wǎng)址:
http://mvnrepository.com/
http://search.maven.org/
http://repository.sonatype.org/content/groups/public/
http://people.apache.org/repo/m2-snapshot-repository/
http://people.apache.org/repo/m2-incubating-repository/ -
案例演示
從maven倉庫中下載
找到要下載的版本
查看pom.xml的依賴
注:演示的是ostermillerutils-1.07.00.jar,實(shí)際我操作的是ostermillerutils-1.08.02.jar
- 操作命令
語法:
mvn install:install-file -Dfile=jar包的位置(參數(shù)一) -DgroupId=groupId(參數(shù)二) -DartifactId=artifactId(參數(shù)三) -Dversion=version(參數(shù)四) -Dpackaging=jar
示例:
mvn install:install-file -Dfile="D:\soft\ostermillerutils-1.08.02-bin\ostermillerutils-1.08.02\ostermillerutils-1.08.02.jar" -DgroupId=org.ostermiller -DartifactId=ostermillerutils -Dversion=1.08.02 -Dpackaging=jar
注:默認(rèn)將jar復(fù)制到 “C:\Users\Administrator.m2\repository\” 下
需要注意以下幾點(diǎn):
- 注意"-"不能缺少 install后面的"-"是沒有空格的
- 注意"-Dfile"中jar包的路徑和jar包的名字.
- 注意看cmd命令提示,查看本地repository中是否成功的復(fù)制了jar包.
- 參數(shù)必須一致,不然會失敗
<!-- https://mvnrepository.com/artifact/org.ostermiller/utils -->
<dependency>
<groupId>org.ostermiller</groupId> ------------(參數(shù)二)
<artifactId>ostermillerutils</artifactId>------(參數(shù)三)
<version>1.08.02</version>---------------------(參數(shù)四)
</dependency>
cmd上的成功示例:

image.png


