向Maven的本地库中添加jar文件
有时我们要用的 maven 依赖项在官方repo库中找不到,然而我们从其他渠道获得了依赖项中的所有jar文件,本文记录了如何向本地库添加jar文件。
从复杂到简单,有三种方法:
- 使用 maven 的仓库管理器(例如Nexus)来架设一个本地仓库服务器
- 使用指令 mvn install:install-file 将jar文件安装到本地仓库
- 通过项目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文件的更多相关文章
- 如何在maven中添加jar包
Maven 中央仓库地址: 1. http://www.sonatype.org/nexus/ 2. http://mvnrepository.com/ (本人推荐仓库) 3. http://repo ...
- maven 如何给web项目添加jar包依赖
maven 如何给web项目添加jar包依赖 CreateTime--2018年4月19日19:06:21 Author:Marydon 开发工具:eclipse 1.打开pom.xml文件--& ...
- 怎样在nexus 中 搜索到远程maven仓库中的jar 文件
怎样在nexus 中 搜索到远程maven仓库中的jar 文件 url: http://www.oschina.net/question/95712_21999 点击Administration菜单下 ...
- 如何在IOS开发中在自己的framework中添加.bunble文件
今天就跟大家介绍一下有关,如何在IOS开发中在自己的framework中添加.bunble文件,该文章我已经在IOS教程网(http://ios.662p.com)发布过来,个人觉得还是对大家有帮助的 ...
- ASP.NET在主题中添加CSS文件
ASP.NET在主题中添加CSS文件 在ASP.NET中,可以使用CSS来控制页面上HTML元素和ASP.NET控件的皮肤.如果在主题文件夹中添加了CSS文件,则在页面应用主题时也会自动应用CSS. ...
- Xcode7 Xcode6 中添加pch文件
在Xcode7 和 Xcode6 中添加.pch文件是一样的,具体操作图文如下: 第一步:在Xcode的项目里,一般在Supporting Files 文件夹下创建,选中Supporting File ...
- cmd中执行jar文件命令(待参数)
cmd中执行jar文件命令(待参数) 1,jar文件路径:F:\products 2,cmd命令: --两个日期参数(空格隔开) java -jar F:\products\analysis.jar ...
- 记录自己在 cmd 中执行 jar 文件遇到的一些错误
记录自己在 cmd 中执行 jar 文件遇到的一些错误 场景: 请求接口,解析接口返回的 JSON 字符串并插入到我们的数据库里面. 情况: 项目在 eclipse 中正常运行,打成 jar 包后在 ...
- 如何在maven项目的pom.xml文件中添加jar包
在使用maven进行项目开发时,我们需要在pom.xml文件中添加自己所需要的jar包.这就要求我们获取jar包的groupId和artifactId. 我们可以在一些maven仓库上搜索我们所需要的 ...
随机推荐
- jQuery旋转木马仿3D效果的图片切换特效代码
用jQuery实现的一款仿3D效果的图片切换特效代码,类似旋转木马一样,幻灯图片以三维视觉上下滑动切换,效果很酷炫,兼容IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜 ...
- 申请邓白氏编码的时候总是提示 Enter a valid Street Address 怎么办?
今天要申请一个苹果开发者公司(Company)账号,然后需要邓白氏编码,然后填写企业的基本信息.其中对于Street Address认真的对照着中文翻译为如下格式: Kang Hesheng buil ...
- Convertion of grey code and binary 格雷码和二进制数之间的转换
以下转换代码摘自维基百科 Wikipedia: /* The purpose of this function is to convert an unsigned binary number to r ...
- 正则获取HTML代码中img的src地址
/// <summary> /// 获得HTML中所有图片的src地址 /// </summary> /// <param name="sHtmlText&qu ...
- 跳转Activity两种方法
摘要:假设从A界面开启另外一个B界面根据是否需要返回数据分为两种方式 一.无需返回数据方式 在A界面中调用startActivity方法进行直接跳转即可 二.需要返回数据方式 1.在A界面中调用sta ...
- python re 模块和基础正则表达式
1.迭代器:对象在其内部实现了iter(),__iter__()方法,可以用next方法实现自我遍历. 二.python正则表达式 1.python通过re模块支持正则表达式 2.查看当前系统有哪些p ...
- GRE与Vxlan网络详解
1. GRE 1.1 概念 GRE全称是Generic Routing Encapsulation,是一种协议封装的格式,具体格式内容见:https://tools.ietf.org/html/rfc ...
- js获取域名
<script language="javascript">//获取域名host = window.location.host;host2=document.domai ...
- Bioinformatics Glossary
原文:http://homepages.ulb.ac.be/~dgonze/TEACHING/bioinfo_glossary.html Affine gap costs: A scoring sys ...
- 【UOJ#228】基础数据结构练习题 线段树
#228. 基础数据结构练习题 题目链接:http://uoj.ac/problem/228 Solution 这题由于有区间+操作,所以和花神还是不一样的. 花神那道题,我们可以考虑每个数最多开根几 ...