加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Maven:指向多个jar的系统依赖关系

发布时间:2020-12-14 16:42:44 所属栏目:Java 来源:网络整理
导读:是否可以在pom中定义一个依赖关系,以便它具有系统的范围,但指向多个jar? 我相信这是非常非正统的,但是,我只是想知道这是否可能.所以这样的东西: dependency groupIdfoo/groupId artifactIdfoo/artifactId version1.0/version scopesystem/scope systemPath
是否可以在pom中定义一个依赖关系,以便它具有系统的范围,但指向多个jar?

我相信这是非常非正统的,但是,我只是想知道这是否可能.所以这样的东西:

<dependency>
  <groupId>foo</groupId>
  <artifactId>foo</artifactId>
  <version>1.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/lib/foo/*.jar</systemPath>
</dependency>

解决方法

首先(我永远不会重复),使用系统范围的依赖关系是不鼓励的,除非你确切地知道你在做什么.从 Dependency Scopes:

system: This dependency is required in some phase of your
project’s lifecycle,but is
system-specific. Use of this scope
is discouraged: This is considered an
“advanced” kind of feature and should
only be used when you truly understand
all the ramifications of its use,
which can be extremely hard if not
actually impossible to quantify
.
This scope by definition renders your
build non-portable. It may be
necessary in certain edge cases. The
system scope includes the
<systemPath> element which points to
the physical location of this
dependency on the local machine. It is
thus used to refer to some artifact
expected to be present on the given
local machine an not in a repository;
and whose path may vary
machine-to-machine. The systemPath
element can refer to environment
variables in its path: ${JAVA_HOME}
for instance.

现在,为了严格地回答你的问题,如果依赖关系在其Class-Path条目中相对地列出了一个MANIFEST.MF,则列出一个指向几个jar的系统范围的依赖关系是可能的.这样的东西(假设“根”依赖在lib中):

Class-Path: ../lib/bar.jar ../lib/foo.jar

但我不推荐这种方法,特别是在你的具体情况下.相反,请看这个previous answer,我将介绍如何设置基于文件的存储库.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读