java left logo
java middle logo
java right logo

Home arrow Other API Tips arrow Ant arrow How to use Uptodate task
Main Menu
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog

Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews

Registered Users: 4118
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
How to use Uptodate task E-mail
User Rating: / 14



Sets a property if a target file or set of target files is more up-to-date than a source file or set of source files. A single source file is specified using the srcfile attribute. A set of source files is specified using the nested <srcfiles> elements. These are FileSets, whereas multiple target files are specified using a nested <mapper> element.

By default, the value of the property is set to true if the timestamp of the source file(s) is not more recent than the timestamp of the corresponding target file(s). You can set the value to something other than the default by specifying the value attribute.

If a <srcfiles> element is used, without also specifying a <mapper> element, the default behavior is to use a merge mapper, with the to attribute set to the value of the targetfile attribute.

Normally, this task is used to set properties that are useful to avoid target execution depending on the relative age of the specified files.


Attribute Description Required
property The name of the property to set. Yes
value The value to set the property to. No; defaults to true.
srcfile The file to check against the target file(s). Yes, unless a nested <srcfiles> element is present.
targetfile The file for which we want to determine the status. Yes, unless a nested <mapper> element is present.

Parameters specified as nested elements


The nested <srcfiles> element allows you to specify a set of files to check against the target file(s).

Note: You can specify either the srcfile attribute or nested <srcfiles> elements, but not both.


The nested <mapper> element allows you to specify a set of target files to check for being up-to-date with respect to a set of source files.

The mapper "to" attribute is relative to the target file, or to the "dir" attribute of the nested srcfiles element.

Since Ant 1.6.3, one can use a filenamemapper type in place of the mapper element.


<uptodate property="xmlBuild.notRequired" 
 targetfile="${deploy}\xmlClasses.jar" >
 <srcfiles dir= "${src}/xml" includes="**/*.dtd"/>


sets the property xmlBuild.notRequired to true if the ${deploy}/xmlClasses.jar file is more up-to-date than any of the DTD files in the ${src}/xml directory.

This can be written as:

<uptodate property="xmlBuild.notRequired">
 <srcfiles dir= "${src}/xml" includes="**/*.dtd"/>
 <mapper type="merge" to="${deploy}\xmlClasses.jar"/>

as well. The xmlBuild.notRequired property can then be used in a <target> tag's unless attribute to conditionally run that target. For example, running the following target:

<target name="xmlBuild" depends="chkXmlBuild" unless="xmlBuild.notRequired">

will first run the chkXmlBuild target, which contains the <uptodate> task that determines whether xmlBuild.notRequired gets set. The property named in the unless attribute is then checked for being set/not set. If it did get set (ie., the jar file is up-to-date), then the xmlBuild target won't be run.

The following example shows a single source file being checked against a single target file:

  <uptodate property="isUpToDate"

sets the property isUpToDate to true if /usr/local/bin/testit is not newer than ${build}/.flagfile.

The following shows usage of a relative mapper.

    <uptodate property="checkUptodate.uptodate">
      <srcfiles dir="src" includes="*"/>
      <mapper type="merge" to="../dest/output.done"/>

    <echo message="checkUptodate result: ${checkUptodate.uptodate}"/>

The previous example can be a bit confusing, so it may be better to use absolute paths:

    <property name="dest.dir" location="dest"/>
    <uptodate property="checkUptodate.uptodate">

      <srcfiles dir="src" includes="*"/>
      <mapper type="merge" to="${dest.dir}/output.done"/>

Source: Apache Ant

 Related Tips

< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.

Name (required)

E-Mail (required)

Your email will not be displayed on the site - only to our administrator

Comment Enable HTML code : Yes No

java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008
Java is a trademark of Sun Microsystems, Inc.