Maven:指向多个jar的系统依赖项 [英] Maven: System dependency pointing to multiple jars

查看:208
本文介绍了Maven:指向多个jar的系统依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在pom中定义依赖关系,使其具有系统范围但指向多个jar?

Is it possible to define a dependency in the pom such that it has the scope of system but points to multiple jars?

我确定这是非常不正统的然而,我只是想知道这是否可能。所以类似于:

I'm sure this is quite unorthodox, however, I was just wondering whether this was even possible. So something like:

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


推荐答案

首先(我永远不会重复它) ,除非您确切知道自己在做什么,否则不建议使用 system 作用域依赖项。来自依赖范围

First (and I'll never repeat it enough), using system scoped dependencies is discouraged unless you know exactly what you're doing. From Dependency Scopes:


系统:在
项目生命周期的某个阶段需要此依赖项,但系统特定于
不建议使用此范围
:这被视为
高级功能,只有当您真正理解
的所有后果时才应使用
使用,
如果不是
实际上无法量化
,这可能会非常困难。
根据定义,此范围使您的
构建成为非可移植的。在某些边缘情况下,它可能是

系统范围包括
< systemPath> 元素,该元素指向

依赖关系的物理位置本地机器。因此,
用于表示某些工件
预计会出现在给定的
本地计算机上而不是存储库中;
,其路径可能因机器对机器而异。 systemPath
元素可以在其路径中引用环境
变量: $ {JAVA_HOME} 例如,

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.

现在,严格回答你的问题,声明与系统的依赖关系指向几个罐子的范围是可能的 IF 依赖项有一个 MANIFEST.MF 相对列出其他JAR在其 Class-Path 条目中。这样的事情(假设根依赖在 lib ):

Now, to strictly answer your question, declaring a dependency with a system scope that would point on several jars is "possible" IF the dependency has a MANIFEST.MF listing other JARs relatively in its Class-Path entry. Something like this (assuming the "root" dependency is in lib):

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

但我不推荐这种方法,特别是在您的特定情况下。相反,请看一下这个之前的回答我描述了如何设置基于文件的存储库。

But I do NOT recommend this approach, especially in your particular case. Instead, have a look at this previous answer where I describe how to setup a file-based repository.

这篇关于Maven:指向多个jar的系统依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆