Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We have inherited an ant build file but now need to deploy to both 32bit and 64bit systems.

The non-Java bits are done with GNUMakefiles where we just call "uname" to get the info. Is there a similar or even easier way to mimic this with ant?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
302 views
Welcome To Ask or Share your Answers For Others

1 Answer

Late to the party, but what the heck...

${os.arch} only tells you if the JVM is 32/64bit. You may be running the 32bit JVM on a 64bit OS. Try this:

<var name ="os.bitness" value ="unknown"/>
<if>
<os family="windows"/>
<then>
    <exec dir="." executable="cmd" outputproperty="command.ouput">
        <arg line="/c SET ProgramFiles(x86)"/>
    </exec>
    <if>
        <contains string="${command.ouput}" substring="Program Files (x86)"/>
        <then>
            <var name ="os.bitness" value ="64"/>
        </then>
        <else>
            <var name ="os.bitness" value ="32"/>
        </else>
    </if>
</then>
<elseif>
    <os family="unix"/>
    <then>
        <exec dir="." executable="/bin/sh" outputproperty="command.ouput">
        <arg line="/c uname -m"/>
        </exec>
        <if>
            <contains string="${command.ouput}" substring="_64"/>
            <then>
                <var name ="os.bitness" value ="64"/>
            </then>
            <else>
                <var name ="os.bitness" value ="32"/>
            </else>
        </if>
    </then>
</elseif>
</if>

<echo>OS bitness: ${os.bitness}</echo>

EDIT: As @GreenieMeanie pointed out, this requires the ant-contrib library from ant-contrib.sourceforge.net


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...