zoukankan      html  css  js  c++  java
  • 向Maven的本地库中添加jar文件

    有时我们要用的 maven 依赖项在官方repo库中找不到,然而我们从其他渠道获得了依赖项中的所有jar文件,本文记录了如何向本地库添加jar文件。

    从复杂到简单,有三种方法:

    1. 使用 maven 的仓库管理器(例如Nexus)来架设一个本地仓库服务器
    2. 使用指令 mvn install:install-file 将jar文件安装到本地仓库
    3. 通过项目pom配置文件引入

    第一种方法有利于团队开发,内容多一点,我打算单独用一篇文章记录。这里介绍其他两种方法:

    使用指令 mvn install:install-file 将jar文件安装到本地仓库

    语法规范:

    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true Where: <path-to-file> the path to the file to load <group-id> the group that the file should be registered under <artifact-id> the artifact name for the file <version> the version of the file <packaging> the packaging of the file e.g. jar

    我们以文件<not-yet-commons-ssl-0.3.17.jar>为例:

    mvn install:install-file -Dfile=e: ot-yet-commons-ssl-0.3.17.jar -DgroupId=org.apache.commons -DartifactId=not-yet-commons-ssl -Dversion=0.3.17 -Dpackaging=jar -DgeneratePom=true

    通过项目pom配置文件引入

    编辑项目pom文件,在依赖项中增加条目,并指定<scope>和<systemPath>。

    还是以文件<not-yet-commons-ssl-0.3.17.jar>为例:

    <dependency> <groupId>org.apache.commons</groupId> <artifactId>not-yet-commons-ssl</artifactId> <version>0.3.17</version> <scope>system</scope> <systemPath>e: ot-yet-commons-ssl-0.3.17.jar</systemPath> </dependency>

    等等,编译后出现一个警告:

    [WARNING] 'dependencies.dependency.systemPath' for org.apache.commons:not-yet-commons-ssl:jar should use a variable instead of a hard-coded path e: ot-yet-commons-ssl-0.3.17.jar @ line 35, column 16
    [WARNING]
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
    [WARNING]
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

    原来是 maven 苦口婆心地告诉我们不要使用诸如 C:Windows 这样的绝对路径,而应使用 ${java.home} 这样的相对路径(变量),否则降低了编译可重现性,并威胁我们以后可能不再支持这种方式。

    嗯,我们可以建立一个 maven 仓库的环境变量来消除这个警告,如果你觉得有这个必要。

  • 相关阅读:
    锋利的jQuery复制粘贴(一)
    使用photoshop以及markman进行快速重构页面的几个步骤
    线程间同步之 semaphore(信号量)
    关于C#中Thread.Join()的一点理解
    无废话WCF入门教程一[什么是WCF]
    Oracle function注释
    throw new DataException("检查服务器是否存在失败:" + ex);
    C# 将数据集以excel的形式输出
    .net 安装remoting服务
    任务计划 每日删除设定目录内的文件(包括文件夹)
  • 原文地址:https://www.cnblogs.com/gugia/p/5006460.html
Copyright © 2011-2022 走看看