views:

98

answers:

3

Hi, 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.

+3  A: 

You can do this with profiles.This will only work in Sun's 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>
Colin Hebert
+1  A: 

Maven Profiles may be helpful to you.

Gopi
+6  A: 

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.)

mdma
Beware, this method assumes you use a 64bits JVM on a 64bits system which isn't always true.Most of the time people uses 32bits JVM on their system 32bits or not.
Colin Hebert
That's not true. A 32-bit vm will return x86 for the architecture even on x64. (If it didn't then it would fail, since trying to load a 64-bit dll under a 32-bit vm will fail.) I run a 64-bit OS, but often use a 32-bit vm. See my edit for an easy way to inspect this system property using maven.
mdma