maven添加本地jar包

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

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

<dependencies>
  <dependency>
    <groupId>xxxgroupId>
    <artifactId>xxxartifactId>
    <version>xxxversion>
    <scope>systemscope>
    <systemPath>${basedir}/xx.jarsystemPath>
  dependency>
dependencies>

但是,在运行jetty 的以及打包的时候,会找不到引用的包,直接pass掉。各种蛋疼,都是maven不熟惹的祸。故去maven官网看了一下文档,捣鼓了好一阵儿,终于找到了一个解决办法:

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

 (1)创建本地仓库: 

<repositories>
  <repository>
    <id>local-repoid>
    <url>file://${basedir}/repourl>
  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.pluginsgroupId>
    <artifactId>maven-install-pluginartifactId>
    <version>2.4version>
    <executions>
        <execution>
            <phase>initializephase>
            <goals>
                <goal>install-filegoal>
            goals>
            <configuration>
                <groupId>xxxgroupId>
                <artifactId>xxxartifactId>
                <version>xxxversion>
                <packaging>jarpackaging>
                <file>${basedir}/xxx.jarfile>
            configuration>
        execution>
    executions>
plugin>

(4) 添加依赖:

<dependency>
    <artifactId>xxxartifactId>
    <groupId>xxxgroupId>
    <version>xxxversion>
dependency>

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

 

你可能感兴趣的:(maven添加本地jar包)