May 27

Previously we covered passing command line arguments to Ant. We can use that to specify the value to be used for arg tag values. Here is an example:

ant -Dargstring="-test -abc file.out" build

In the build script we have the following:

  <java classname="test.Main" fork="yes" >
    <arg value="${argstring}"/>
  </java>

This will result in the arguments “-test -abc file.out” being passed to the java call in the build script.

written by objects \\ tags: , , , ,

May 27

Sometimes you need to pass an argument on the command line to be used by your Ant build.

You can achieve this by passing it as a system property using the -D option. eg.

ant -Dmyarg=abc build

You can then access that system property in your build script as ${myarg}. eg. The following will replace all occurrences of ‘@@@’ with the value of myarg specified on the command line (‘abc’ in the above example)

<replace dir="${src}" token="@@@" value="${myarg}">
  <include name="**/*.html"/>
</replace>

written by objects \\ tags: , , ,

Jul 16

By default ant looks for a build file name build.xml if one is not explicitly specified. To specify an alternate build file name you need to use the -buildfile command line option. For example to execute the compile target in the build file name mybuild.xml you would run:
ant -buildfile mybuild.xml compile

written by objects \\ tags: ,