2010-08-17 23 views
8

我有一個Maven倉庫設置爲託管一些dll,但我需要我的Maven項目下載不同的dll,具體取決於使用的JVM是x86還是x64。如果使用的JVM是x86或x64,則以不同的方式解決Maven依賴關係?

例如,在運行x86版本JVM的計算機上,我需要從存儲庫中下載ABC.dll作爲依賴項,但在另一臺運行JVM的x64版本的計算機上,我需要下載XYZ .dll代替。

我該怎麼做呢?一個示例pom.xml文件會很好。

+0

你將如何從java訪問這些dll? – Njax3SmmM2x2a0Zf7Hpd 2014-06-26 17:45:11

回答

5

您可以使用配置文件完成此操作。這隻適用於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> 
15

這將適用於任何虛擬機。您可以根據環境使用profiles進行替代配置。

配置文件中包含的激活塊,它描述何時激活該配置文件,然後通常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 - 只有,因此您可能還需要在<os>標籤下添加<family>Windows</family>

編輯:當在64位操作系統上混合32位虛擬機,你可以通過運行maven的目標

mvn help:evaluate

,然後輸入看看有什麼價值的虛擬機給人以os.arch系統屬性

${os.arch}

可替換地,目標help:system列出了所有的系統屬性(沒有特定的順序)。

+0

請注意,此方法假定您在64位系統上使用64位JVM,但並非總是如此。 大部分時間,人們在系統上使用32位JVM或32位JVM。 – 2010-08-17 10:11:44

+1

這是不正確的。即使在x64上,32位vm也會爲架構返回x86。 (如果沒有,那麼它會失敗,因爲試圖在32位vm下加載64位dll將失敗。)我運行64位操作系統,但通常使用32位vm。查看我的編輯,瞭解使用maven檢查此係統屬性的簡單方法。 – mdma 2010-08-17 10:22:45

+3

amd64 for 64 bits platform – revo 2013-07-24 20:19:06

相關問題