zoukankan      html  css  js  c++  java
  • maven添加本地jar包

    今天遇到一个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不是太熟,的确花了不少时间去看资料。特在此记录,一来留个笔记,而来希望能帮助到遇到同样问题的人。

  • 相关阅读:
    Linux的iptables和netfilter
    adb安装电视apk
    令牌桶实现服务器限流
    观察者模式代码实现
    Windows系统安装Oracle 11g 数据库
    Gitlab安装后 启动之后报错502
    Git两库合并历史记录
    Maven打包时指定对应环境的配置文件
    HierarchicalDataTemplateGridControl
    自定义CommandHandler
  • 原文地址:https://www.cnblogs.com/dongying/p/4293458.html
Copyright © 2011-2022 走看看