maven 手動將本地jar新增到Maven倉庫
實際專案中pom.xml依賴寫法:
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>3.1.0.RELEASE</version>
- </dependency>
Maven 安裝 JAR 包的命令是:
- mvn install:install-file
- -Dfile=jar包的位置
- -DgroupId=上面的groupId
- -DartifactId=上面的artifactId
- -Dversion=上面的version
- -Dpackaging=jar
例如我的這個spring-context-support-3.1.0.RELEASE.jar 檔案放在了"D:\mvn\"中
則命令為:
mvn install:install-file
-Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar
-DgroupId=org.springframework
-DartifactId=spring-context-support
-Dversion=3.1.0.RELEASE
-Dpackaging=jar
注意:任何路徑和名稱不要有中文和空格,以防出現莫名其妙的錯誤。
還可以解決本地倉庫是從別人那邊複製的,但是需要的jar包中央倉庫不存在,導致的執行package時出現以下異常
- Failed to execute goal on project relayserver: Could not resolve dependencies for project com.xxx:xxx:war:1.0-SNAPSHOT: Failure to find xxx.xxx:xxx:jar:1.0 in http://maven.aliyun
- .com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus-aliyun has elapsed or updates are forced
二、不講jar包新增到本地倉庫也可在maven工程中使用外部jar包的做法:
<!-- (引數一):下載到本地的ojdbc-10.2.0.4.0.jar包的真實存放路徑 -->
<dependency>
<groupId>ojdbc</groupId>-----------------(引數二)
<artifactId>ojdbc</artifactId>-----------(引數三)
<version>10.2.0.4.0</version>------------(引數四)
</dependency>
語法:
mvn install:install-file -Dfile=jar包的位置(引數一) -DgroupId=groupId(引數二) -DartifactId=artifactId(引數三) -Dversion=version(引數四) -Dpackaging=jar
我把“ojdbc-10.2.0.4.0.jar”放到了“D:\Program Files\mvn\”下,
注意:“Program Files”中間有空格,所以要加雙引號,另外三個引數,從上面複製過來即可,下面是我安裝ojdbc-10.2.0.4.0.jar包使用的命令:
mvn install:install-file -Dfile="D:\Program Files\mvn\ojdbc-10.2.0.4.0.jar" -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar
需要注意以下幾點:
1.注意"-"不能缺少 install後面的"-"是沒有空格的
2.注意"-Dfile"中jar包的路徑和jar包的名字.
3.注意看cmd命令提示,檢視本地repository中是否成功的複製了jar包.
重點:Jar包預設都安裝在“C:\Users\Administrator\.m2\repository\”下,其實上面的(引數二,引數三,引數四)就是指定安裝具體的安裝路徑。
(以後也可以根據自己需求進行更改引數二,三,四,其實就是更改安裝路徑)。