今天遇到一个mavan仓库中没有的jar包, 故只能添加本地jar包, 花了很多时间找资料,终于OK。故在此记录。apache
1. 第一次,在网上看到说能够用<systemPath> 解决, 以下:maven
<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官网看了一下文档,捣鼓了好一阵儿,终于找到了一个解决办法:url
2. 建立本地仓库,以plugin的形式进行安装:spa
(1)建立本地仓库: 插件
<repositories> <repository> <id>local-repo</id> <url>file://${basedir}/repo</url> </repository> </repositories>
(2)将本地库安装到maven:code
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是你以前建立的本地仓库的路径)。blog
(3) 以插件形式安装:ci
<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不是太熟,的确花了很多时间去看资料。特在此记录,一来留个笔记,而来但愿能帮助到遇到一样问题的人。it