ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antoine Levy-Lambert" <>
Subject Re: Can i call execute() on a std task from within a custom task?
Date Sat, 12 Apr 2003 17:22:53 GMT

> For example, in my product, i have a list of jar files that i need to
> create: say "a.jar", "b.jar", and "c.jar".
> I could do something like this...
>     <target name="makejars">
>         <jar destfile="a.jar">
>             <fileset dir="${build.classdir}" includes="files_for_a_jar"/>
>         </jar>
>         <jar destfile="b.jar">
>             <fileset dir="${build.classdir}" includes="files_for_b_jar"/>
>         </jar>
>         <jar destfile="c.jar">
>             <fileset dir="${build.classdir}" includes="files_for_c_jar"/>
>         </jar>
>     </target>
> However, i'm creating a build pattern/system for multiple products in my
> company, so at build time, i the definition of what jar files are to be
> created is defined in a custom configuration file (that i already wrote a
> custom parser for since it's not in anything "standard").  The jars i'm
> creating are completly based in the configuration.  It could be anything
> such as "a.jar", "b.jar", and "c.jar" like above...but it also could be
> "a.jar", "c.jar", and d.jar...or even just "a.jar".

I wonder whether it is not possible to what you want without custom tasks.
One possibility (untested) would be using the ant-contrib on top of ant.
There is there a foreach task. If you write the list of jarfiles that you
want to generate in a property file in a format which is
recognized as list by foreach, then you could just run antcall on a generic
jar target passing the name of the jar file and the files to be included as
If there is a limitative list of jar files that you may want to create in
your build, you can also make normal ant targets for each of a, b, c and
d.jar and create properties such as a.jar.desired, b.jar.desired,
c.jar.desired, d.jar.desired in your property file
Your build file would then look like this

<property file=""/>
<!-- looks like that
#b.jar is not desired, so it is omitted
#c.jar is also not desired
<target name="all" depends="a.jar,b.jar,c.jar,d.jar"/>
<target name="a.jar" if="a.jar.desired">
<!-- instructions to create a.jar -->
<target name="b.jar" if="b.jar.desired">
<!-- instructions to create b.jar -->
<target name="c.jar" if="c.jar.desired">
<!-- instructions to create c.jar -->
<target name="d.jar" if="d.jar.desired">
<!-- instructions to create d.jar -->

this is even better, because this solution only relies on normal core ant

> Is it legal to call the Java API "execute()" method on a standard task
> from within a custom task?
Yes this is legal
grep in ant for getProject().createTask() to see how this is done

here an example from an optional task

  execTask = null;
            execTask = (ExecTask) getTask().getProject().createTask("exec");
            execTask.setDir(new File("."));
            if (getCombinedClasspath() != null)  {


            if (java2iiopdebug) {
            // ejb jar file to verfiy
            log("Calling iastool", Project.MSG_VERBOSE);


View raw message