如果正在使用的JVM是x86或x64,则会解决Maven依赖关系? [英] Resolving a Maven dependency differently if the JVM in use is x86 or x64?
问题描述
所以例如,在运行x86版本的JVM的计算机上,我需要ABC.dll作为依赖从存储库下载,但在另一台运行x64版本的JVM,我需要它下载XYZ.dll。
我该怎么做?一个例子pom.xml文件会很好。
这将适用于任何虚拟机。您可以使用个人资料根据环境进行备用配置。
一个配置文件包含一个激活块,它描述何时使配置文件处于活动状态,后跟通常的pom元素,如依赖关系:
<个人资料>
<个人资料>
< activate>
< os>
< arch> x86< / arch>
< / os>
< / activation>
<依赖关系>
<依赖关系>
<! - 您的32位依赖关系 - >
< / dependency>
< / dependencies>
< / profile>
<个人资料>
< activate>
< os>
< arch> x64< / arch>
< / os>
< / activation>
<依赖关系>
<! - 您的64位依赖关系 - >
< / dependencies>
< / profile>
< / profiles>
如你所提到的DLL,我假设这是仅Windows,所以你可能还想在< os>
标签下添加< family> Windows< / family>
编辑:在64位操作系统上混合32位虚拟机时,可以看到虚拟机给出的值为$ code> os.arch 系统属性通过运行maven目标
mvn帮助:评估
然后输入
$ {os.arch}
或者,目标 help:system
列出所有系统属性(没有特定的顺序)。
I have a Maven repository set up to host some dlls, but I need my Maven projects to download different dlls depending on whether the JVM in use is x86 or x64.
So for example, on a computer running an x86 version of the JVM I need ABC.dll to be downloaded from the repository as a dependency, but on another computer running an x64 version of the JVM, I need it download XYZ.dll instead.
How would I go about doing this? An example pom.xml file would be nice.
This will work on any VM. You can use profiles to have alternate configurations according to the environment.
A profile contains an activation block, which describes when to make the profile active, followed by the usual pom elements, such as dependencies:
<profiles>
<profile>
<activation>
<os>
<arch>x86</arch>
</os>
</activation>
<dependencies>
<dependency>
<!-- your 32-bit dependencies here -->
</dependency>
</dependencies>
</profile>
<profile>
<activation>
<os>
<arch>x64</arch>
</os>
</activation>
<dependencies>
<!-- your 64-bit dependencies here -->
</dependencies>
</profile>
</profiles>
As you mentioned DLLs, I'm assuming this is Windows-only, so you may also want to add <family>Windows</family>
under the <os>
tags.
EDIT: When mixing 32-bit VM on a 64-bit OS, you can see what value the VM is giving to the os.arch
system property by running the maven goal
mvn help:evaluate
And then entering
${os.arch}
Alternatively, the goal help:system
lists all system properties (in no particular order.)
这篇关于如果正在使用的JVM是x86或x64,则会解决Maven依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!