有时我们要用的 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:\not-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:\not-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:\not-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 仓库的环境变量来消除这个警告,如果你觉得有这个必要。

向Maven的本地库中添加jar文件的更多相关文章

  1. 如何在maven中添加jar包

    Maven 中央仓库地址: 1. http://www.sonatype.org/nexus/ 2. http://mvnrepository.com/ (本人推荐仓库) 3. http://repo ...

  2. maven 如何给web项目添加jar包依赖

      maven 如何给web项目添加jar包依赖 CreateTime--2018年4月19日19:06:21 Author:Marydon 开发工具:eclipse 1.打开pom.xml文件--& ...

  3. 怎样在nexus 中 搜索到远程maven仓库中的jar 文件

    怎样在nexus 中 搜索到远程maven仓库中的jar 文件 url: http://www.oschina.net/question/95712_21999 点击Administration菜单下 ...

  4. 如何在IOS开发中在自己的framework中添加.bunble文件

    今天就跟大家介绍一下有关,如何在IOS开发中在自己的framework中添加.bunble文件,该文章我已经在IOS教程网(http://ios.662p.com)发布过来,个人觉得还是对大家有帮助的 ...

  5. ASP.NET在主题中添加CSS文件

    ASP.NET在主题中添加CSS文件 在ASP.NET中,可以使用CSS来控制页面上HTML元素和ASP.NET控件的皮肤.如果在主题文件夹中添加了CSS文件,则在页面应用主题时也会自动应用CSS. ...

  6. Xcode7 Xcode6 中添加pch文件

    在Xcode7 和 Xcode6 中添加.pch文件是一样的,具体操作图文如下: 第一步:在Xcode的项目里,一般在Supporting Files 文件夹下创建,选中Supporting File ...

  7. cmd中执行jar文件命令(待参数)

    cmd中执行jar文件命令(待参数) 1,jar文件路径:F:\products 2,cmd命令: --两个日期参数(空格隔开) java -jar F:\products\analysis.jar ...

  8. 记录自己在 cmd 中执行 jar 文件遇到的一些错误

    记录自己在 cmd 中执行 jar 文件遇到的一些错误 场景: 请求接口,解析接口返回的 JSON 字符串并插入到我们的数据库里面. 情况: 项目在 eclipse 中正常运行,打成 jar 包后在 ...

  9. 如何在maven项目的pom.xml文件中添加jar包

    在使用maven进行项目开发时,我们需要在pom.xml文件中添加自己所需要的jar包.这就要求我们获取jar包的groupId和artifactId. 我们可以在一些maven仓库上搜索我们所需要的 ...

随机推荐

  1. elasticsearch suggest 的几种使用-completion 的基本 使用

    在lucene里面,suggest 的支持非常完善,可以随心所欲的定制: 但是在es中使用起来就没有那么方便了. es给suggest 分类4类:term :phrase: completion: c ...

  2. Css--深入学习之切角

    本文是作者从别的网站和文章学习了解的知识,简单做了个笔记,想要学习更多的可以参考这里:[css进阶]伪元素的妙用--单标签之美,奇思妙想 带切角的矩形: 该图来源于(奇思妙想) Css代码: .not ...

  3. 51Nod-1091 线段的重叠

    51Nod 1091:  http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1091   1091 线段的重叠 基准时间限制: ...

  4. virtual memory exhausted: Cannot allocate memory

    ~$free total used free shared buffers cached Mem: 1017832 784328 233504 356 12844 14692 -/+ buffers/ ...

  5. 【C#】C#容易忽视的错误

    1.string 拼接站内存,前提是字符串比较多的时候string 字符串类型拼接占内存,解决方法就是用 StringBuilder和String.Format2.不知道内置的验证数据类型的方法. ; ...

  6. jQuery之Ajax--底层接口

    1. $.ajax()方法:是jQuery最底层的Ajax实现.它的结构为:$.ajax(options).该方法只有一个参数,但在这个对象里面包含了$.ajax()方法所需要的请求设置以及回调函数等 ...

  7. 重写navigationController的push方法后,出现卡顿现象

    在使用navigation的pushViewController进行push的时候,两个页面间的动画会出现卡顿一下再推出的效果,是因为iOS7 viewController背景颜色的问题,看到大神的博 ...

  8. eclipse-将同一个文件分屏显示

    windows-editor-toggle split editor 效果图

  9. 控件之媒体控件: Image, MediaElement

    Image - 图片控件 MediaElement - 播放视频或音频的控件 示例1.Image 的 DemoImageDemo.xaml <Page x:Class="XamlDem ...

  10. delphi 默认值

    只有全局变量才可以赋初值 i:integer=0;