Maven 添加第三方Jar包到本地repositories

由于有些Jar包不是开源的,在maven remote repositories找不到相应的包,所以得通过自有的Jar包在local repositories中添加jar。然后在pom.xml中添加相应的dependency,就能用本地的jar了。 

首先,在本地在添加Jar,它的格式为: 

Java代码   收藏代码
  1. mvn install:install-file  
  2.   -Dfile=<path-to-file>  
  3.   -DgroupId=<group-id>  
  4.   -DartifactId=<artifact-id>  
  5.   -Dversion=<version>  
  6.   -Dpackaging=<packaging>  
  7.   -DgeneratePom=true  
  8.   
  9. Where: <path-to-file>  the path to the file to load  
  10.        <group-id>      the group that the file should be registered under  
  11.        <artifact-id>   the artifact name for the file  
  12.        <version>       the version of the file  
  13.        <packaging>     the packaging of the file e.g. jar  


然后将相应的jar拷到对应的目录下,在pom.xml文件中添加相应的denpendency,它的格式为: 
Java代码   收藏代码
  1. <dependency>  
  2.    <groupId>group-a</groupId>  
  3.    <artifactId>artifact-a</artifactId>  
  4.    <version>1.0</version>  
  5. </dependency  


下面提供一个样例,这里我要用到weblogic,本地有自有weblogic.jar,如是, 
1.  
Java代码   收藏代码
  1. mvn install:install-file  
  2.   -Dfile=D:\lib\weblogic.jar  
  3.   -DgroupId=weblogic  
  4.   -DartifactId=weblogic  
  5.   -Dversion=10.3  
  6.   -Dpackaging=jar  
  7.   -DgeneratePom=true  


将weblogic.jar拷到C:\Documents and Settings\s\.m2\repository\weblogic\weblogic路径下。 

2.  
Java代码   收藏代码
  1. <dependency>  
  2.       <groupId>weblogic</groupId>  
  3.       <artifactId>weblogic</artifactId>  
  4.       <version>10.3</version>  
  5.    </dependency>  


然后在当前pom.xml路径下运行mvn package. 

但奇怪的是编译不通过,出现如下错误: 

Could not resolve dependencies for project com.sx.teest1:test1:jar:1.0-SNAPSHOT: Failure to find weblogic:weblogic:jar:10.3 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1] 


在网上找了很久是update机制的问题,但是在.setting.xml文件后还是出现同样的错,苦思不得其解,然后比较了denpendency能使用的jar和这个denpendency的不同之处,最后发现刚才拷过来的jar没有相应的改文件名,这里由于刚才install的是10.3版本的jar,所以weblogic.jar应该改为weblogic-10.3.jar,改了之后再次运行就能通过了。看来还是自己粗心大意了。拷jar包的时候一定要相应的改jar包的名字。 

另外还发现在Install的时候文件路径名不要有空格,否则会出现一些诡异的错误会让你崩溃的! 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值