I'm using ant to compile a Java application. The problem is some of the devs are on win 7 and others are on xp and vista. Part of the compiling is to build an msi using WIX, on win7 this is one directory and on xp and vista it's in another.
The ant task is controlled in Maven. I'm after a way of telling the difference between windows os's in ant with a conditional tag to set the wix directory. Any ideas?
I know it will be in this format:
<if>
<condition property="isWin7">
Check for windows 7
</condition>
<then>
set wix path to win 7 installation
</then>
<else>
set to vista/xp wix installation
</else>
</if>
Any help would be great.
It is the most complete Java build and deployment tool available. It is platform neutral and can handle platform specific properties, such as file separators. It can be used to perform platform specific tasks such as modifying the modified time of a file using 'touch' command. Ant scripts are written using plain XML.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
It looks like the ANT <condition>
can test for name, family & version of operating system:
Based on that link, there are some properties related to OS that we can query. One is the normal family
property used in the common code:
<!-- CHECK FOR WINDOWS FAMILY OS -->
<condition property="is_windows">
<os family="windows"/>
</condition>
My version of ANT does not print out a resolved value for ${os.family}
.
There is also:
Here's a demo script I made to show the use of these properties:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="build" >
<!-- CHECK FOR WINDOWS FAMILY OS -->
<condition property="is_windows">
<os family="windows"/>
</condition>
<condition property="is_windows_7">
<os name="Windows 7"/>
</condition>
<!-- DISPLAYS WINDOWS OS -->
<target name="display_windows" if="is_windows" >
<echo message="OS Family is: Windows" />
</target>
<target name="build" >
<antcall target="display_windows" />
<echo message="OS Name is: ${os.name}" />
<echo message="OS Architecture is: ${os.arch}" />
<echo message="OS Version is: ${os.version}" />
</target>
</project>
Since answering this question, the code above has been promoted to our production build system, where it is providing shared functionality across Windows & Mac.
@thekbb made a good suggestion to remove the <antcall target="display_windows" />
, and update the target definition to depend on display_windows
as per the below code:
<target name="build" depends="display_windows">
<echo message="OS Name is: ${os.name}" />
<echo message="OS Architecture is: ${os.arch}" />
<echo message="OS Version is: ${os.version}" />
</target>
This based on the fact that antcall
launches a new instance of ant in a new JVM. Some users may find this optimisation easier to understand; others may want to do this for performance reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With