我设置了一个 Maven 存储库来托管一些 dll,但我需要我的 Maven 项目来下载不同的 dll,具体取决于使用的 JVM 是 x86 还是 x64。
因此,例如,在运行 x86 版本的 JVM 的计算机上,我需要将 ABC.dll 作为依赖项从存储库下载,但在另一台运行 x64 版本的 JVM 的计算机上,我需要下载 XYZ.dll。
我该怎么做呢?一个示例 pom.xml 文件会很好。
我设置了一个 Maven 存储库来托管一些 dll,但我需要我的 Maven 项目来下载不同的 dll,具体取决于使用的 JVM 是 x86 还是 x64。
因此,例如,在运行 x86 版本的 JVM 的计算机上,我需要将 ABC.dll 作为依赖项从存储库下载,但在另一台运行 x64 版本的 JVM 的计算机上,我需要下载 XYZ.dll。
我该怎么做呢?一个示例 pom.xml 文件会很好。
这适用于任何虚拟机。您可以使用配置文件根据环境进行备用配置。
配置文件包含一个激活块,它描述了何时使配置文件处于活动状态,然后是常用的 pom 元素,例如依赖项:
<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>
正如您提到的 DLL,我假设这仅适用于 Windows,因此您可能还想<family>Windows</family>
在<os>
标签下添加。
os.arch
编辑:在 64 位操作系统上混合 32 位 VM 时,您可以通过运行 maven 目标查看 VM 赋予系统属性的值
mvn help:evaluate
然后进入
${os.arch}
或者,目标help:system
列出所有系统属性(不按特定顺序)。
您可以使用配置文件来执行此操作。这仅适用于 Sun 的 JVM。
<profiles>
<profile>
<id>32bits</id>
<activation>
<property>
<name>sun.arch.data.model</name>
<value>32</value>
</property>
</activation>
<dependencies>
...
</dependencies>
</profile>
<profile>
<id>64bit</id>
<activation>
<property>
<name>sun.arch.data.model</name>
<value>64</value>
</property>
</activation>
<dependencies>
...
</dependencies>
</profile>
</profiles>
Maven Profiles可能对您有所帮助。