maven 手动将本地jar添加到Maven仓库

https://blog.csdn.net/a491857321/article/details/51085167

实际项目中pom.xml依赖写法:

[html] view plain copy

  1. <dependency>  
  2.     <groupId>org.springframework</groupId>  
  3.     <artifactId>spring-context-support</artifactId>  
  4.     <version>3.1.0.RELEASE</version>  
  5. </dependency>  

Maven 安装 JAR 包的命令是:

[html] view plain copy

  1. mvn install:install-file   
  2. -Dfile=jar包的位置   
  3. -DgroupId=上面的groupId   
  4. -DartifactId=上面的artifactId   
  5. -Dversion=上面的version   
  6. -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时出现以下异常

[plain] view plain copy

  1. 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
  2. .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包的做法:

将下载到本地的JAR包手动添加到Maven仓库

<!-- https://mvnrepository.com/artifact/ojdbc/ojdbc -->

<!-- (参数一):下载到本地的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\”下,其实上面的(参数二,参数三,参数四)就是指定安装具体的安装路径。

(以后也可以根据自己需求进行更改参数二,三,四,其实就是更改安装路径)。

ojdbc-10.2.0.4.0.jar包安装完成:

猜你喜欢

转载自blog.csdn.net/asd657321/article/details/84315057