views:

3430

answers:

4

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?

+1  A: 

You can just pass a parameter into the build file with the value you want. For example, if your target is dist:

ant -Dbuild.target=32 dist

or

ant -Dbuild.target=64 dist

and then in your Ant build script, take different actions depending on the value of the ${build.target} property (you can also use conditions to set a default value for the property if it is not set).

Or, you can check the value of the built-in system properties, such as ${os.arch}.

matt b
A: 

os.arch does not work very well, another approach is asking the JVM, for example:

    ~$ java -d32 test
    Mon Jun 04 07:05:00 CEST 2007
    ~$ echo $?
    0
    ~$ java -d64 test
    Running a 64-bit JVM is not supported on this platform.
    ~$ echo $?
    1

That'd have to be in a script or a wrapper.

Vinko Vrsalovic
A: 

Assuming you are using ANT for building Java Application, Why would you need to know if it is a 32 bit arch or 64-bit? We can always pass parameters to ant tasks. A cleaner way would be to programmaticaly emit the system properties file used by Ant before calling the actual build. There is this interesting post http://forums.sun.com/thread.jspa?threadID=5306174.

questzen
+5  A: 

you can get at the java system properties (http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties()) from ant with ${os.arch}. other properties of interest might be os.name, os.version, sun.cpu.endian, and sun.arch.data.model.

Ray Tayek
Thanks, that sounds like the sanest approach. Will try that.
HD