ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <>
Subject Re: Number expression in Ant?
Date Mon, 25 Oct 2010 03:19:14 GMT
On Sun, Oct 24, 2010 at 10:31 PM, hezjing <> wrote:
> Imagine that I have a property with the value "100", then I want to add 50
> to it and get the result as 150.

Ant isn't a programming language, so it doesn't have a lot of things
you'd think a programming language would have -- such as numeric

You can take a look at the Antcontrib package
<> that many sites use. Antcontrib
contains such tasks that can emulate for loops, if/else statements,
etc. It also has a few property enhancement capabilities like "math".

You can do this in two ways:

<property name="add1" value="100"/>
<property name="add2" value="50"/>

<!-- Method #1 -->
<math result="sum1"

<!-- Method #2 -->
<math result="sum2"
   <op type="+">
       <num value="${add1}"/>
       <num value="${add2}"/>

As an optional package, you need to do a <taskdef> and add in the
antcontrib.jar file to your libpath.

I highly recommend that you create a special directory in your project
called "antlib", place the antcontrib jarfile there, and then add this
to your build.xml:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <fileset dir="${basedir}/antlib"/>

This way, people can use your build.xml without having to install the
antcontrib jar file to install antcontrib and configure their ant
installation to run your build. This way, the antcontrib jar is simply
in your project and is a subdirectory from your build.xml file.

David Weintraub

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message