您的位置:首页 > 其它

maven添加本地jar包

2016-06-16 12:08 417 查看
今天遇到一个mavan仓库中没有的jar包, 故只能添加本地jar包, 花了不少时间找资料,终于OK。故在此记录。

1. 第一次,在网上看到说可以用<systemPath> 解决, 如下:

<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>xxx</version>
<scope>system</scope>
<systemPath>${basedir}/xx.jar</systemPath>
</dependency>
</dependencies>
但是,在运行jetty 以及打包的时候,会找不到引用的包,直接pass掉。各种蛋疼,都是maven不熟惹的祸。故去maven官网看了一下文档,捣鼓了好一阵儿,终于找到了一个解决办法:

2. 创建本地仓库,以plugin的形式进行安装:

 (1)创建本地仓库: 

<repositories>
<repository>
<id>local-repo</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>
(2)将本地库安装到maven:

mvn install:install-file -Dfile=<jar-path> -DgroupId=<group>
-DartifactId=<artifactId> -Dversion=<version> -Dpackaging=<packaging> -DlocalRepositoryPath=<path>


(注:参数说明:jar-path 为你的jar所在路径, group,artifactId, version 这个不多说,  packaging 为jar或war,  DlocalRepositoryPath是你之前创建的本地仓库的路径)。

 (3)  以插件形式安装:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>xxx</version>
<packaging>jar</packaging>
<file>${basedir}/xxx.jar</file>
</configuration>
</execution>
</executions>
</plugin>
  (4) 添加依赖:

<dependency>
<artifactId>xxx</artifactId>
<groupId>xxx</groupId>
<version>xxx</version>
</dependency>
ok, 到此就ok啦。 由于对maven不是太熟,的确花了不少时间去看资料。特在此记录,一来留个笔记,而来希望能帮助到遇到同样问题的人。

原文链接:http://www.cnblogs.com/dongying/p/4293458.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: