java left logo
java middle logo
java right logo

Home arrow Other API Tips
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 PreSetDef task E-mail
User Rating: / 1



The preset definition generates a new definition based on a current definition with some attributes or elements preset.

since Ant 1.6

The resolution of properties in any of the attributes or nested text takes place with the definition is used and not when the preset definition is defined.


Attribute Description Required
name the name of the new definition Yes
uri The uri that this definition should live in. No

Parameters specified as nested elements

another type with attributes or elements set

The <presetdef> task takes one nested element as a parameter. This nested element can be any other type or task. The attributes and elements that need to be preset are placed here.


The following fragment defines a javac task with the debug, deprecation srcdir and destdir attributes set. It also has a src element to source files from a generated directory.
<presetdef name="my.javac">
   <javac debug="${debug}" deprecation="${deprecation}"
          srcdir="${src.dir}" destdir="${classes.dir}">
      <src path="${gen.dir}"/>

This can be used as a normal javac task - example:
The attributes specified in the preset task may be overridden - i.e. they may be seen as optional attributes - example:
<my.javac srcdir="${test.src}" deprecation="no"/>

One may put a presetdef definition in an antlib. For example suppose the jar file antgoodies.jar has the antlib.xml as follows:
   <taskdef resource="com/acme/antgoodies/"/>
   <!-- Implement the common use of the javac command -->
   <presetdef name="javac">

      <javac deprecation="${deprecation}" debug="${debug}"
             srcdir="src" destdir="classes"/>
One may then use this in a build file as follows:
<project default="example" 

   <target name="example">
      <!-- Compile source -->
      <antgoodies:javac srcdir="src/main"/>
      <!-- Compile test code -->
      <antgoodies:javac srcdir="src/test"/>


The following is an example of evaluation of properties when the definition is used:

<target name="defineandcall">
   <presetdef name="showmessage">

      <echo>message is '${message}'</echo>
   <property name="message" value="Message 1"/>

   <antcall target="called">
      <param name="message" value="Message 2"/>
<target name="called">

The command ant defineandcall results in the output:

[showmessage] message is '${message}'
[showmessage] message is 'Message 1'

[showmessage] message is 'Message 2'

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.