Ant

From miki
Jump to navigation Jump to search

ant is the Java based make tool.

Properties

Properties are immutable

<project name="demo" default="demo">
    <target name="demo" >
        <property name="aProperty" value="foo" />
        <property name="aProperty" value="bar" /> <!-- already defined; no effect -->
        <echo message="Property value is '${aProperty}'" /> <!-- Displays 'foo' -->
    </target>
</project>

Environment Variables

<property environment="env"/>

provides all environment variables as Ant properties prefixed by "env.". For example, CLASSPATH would be accessible in Ant as ${env.CLASSPATH} (ref [1]).

Define property from environment with default value

Reference: [2]

First solution, using a conditional part:

<property environment="env"/>
<condition property="fileTargetName" value="${env.RELEASE_VER}" else="dev">
    <isset property="env.RELEASE_VER" />
</condition>

From the manual, documentation on the <condition> tag:

Attribute Description Required
property The name of the property to set. Yes
value The value to set the property to. Defaults to "true". No
else The value to set the property to if the condition evaluates to false. By default the property will remain unset. Since Ant 1.6.3 No

Second solution, using the fact that properties are immutable:

<property environment="env"/>
<property name="env.RELEASE_VER" value="dev"/>

Compilation

<javac source="1.4" srcdir="${sources.dir}" destdir="${classes.dir}/" listfiles="true" debug="true" includeAntRuntime="false" includeJavaRuntime="false" >
  <bootclasspath refid="J9Classpath" />
  <classpath refid="compile.extraclasspath" />
</javac>

To add a compilation argument, for instance change encoding to iso-8859-1:

<javac source="1.4" srcdir="${sources.dir}" destdir="${classes.dir}/" listfiles="true" debug="true" includeAntRuntime="false" includeJavaRuntime="false" >
  <compilerarg line="-encoding iso-8859-1"/> 
  <bootclasspath refid="J9Classpath" />
  <classpath refid="compile.extraclasspath" />
</javac>