ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: property set in sub-task not defined
Date Mon, 17 Mar 2003 20:46:09 GMT
Using pure Ant:

<target name="init" depends="-lib.dir.exists?, -set.lib.classpath">
  <property name="lib.classpath" value="" />

<target name="-lib.dir.exists?">
   <available file="${lib.dir}" type="dir"
              property="lib.dir.exists" />

<target name="-set.lib.classpath" if="lib.dir.exists" >
  <path id="lib.classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar" />
  <property name="lib.classpath" refid="lib.classpath" />

Using Ant-contrib would be nicer of course. Maybe one day it will make it to
Ant: some committer seem to prefer spaghetti Ant as above than an <if>, but
maybe just maybe the wind is turning from recent posts on ant-dev... --DD

-----Original Message-----
From: Pedro Salazar [] 
Sent: Monday, March 17, 2003 2:33 PM
To: Ant Users List
Subject: RE: property set in sub-task not defined


yes the "depends" should work, but it's not nice using the "depends" (I
think) because there are some variables that I don't have yet (lib.dir),
that are set in my main target.

My real case that I'm working is making a content classpath of the
directory $(lib.dir) if it exists, and put it "" (blank) if not to avoid
the string "${lib.classpath}. 

I cannot use the <fileset> directly only without verifying that the
directory exists, otherwise it throws an error. So, I'm trying to verify
it before:

<target name="init" />
      file="${lib.dir}" type="dir" 
    <antcall target="set_lib.classpath" />
    <antcall target="clear_lib.classpath" />

<target name="set_lib.classpath" if="lib_dir.exists" >
    <path id="lib.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
    <property name="lib.classpath" refid="lib.classpath" />
<target name="clear_lib.classpath" unless="lib_dir.exists" >
    <property name="lib.classpath" value="" />

Do you have any approach instead using the depends (that would make very

Pedro Salazar.

On Mon, 2003-03-17 at 20:12, Dominique Devienne wrote:
> Use the depends attribute of target instead of antcall/ant. --DD
> -----Original Message-----
> From: Pedro Salazar [] 
> Sent: Monday, March 17, 2003 2:11 PM
> To:
> Subject: property set in sub-task not defined
> Greetings,
> I'm trying to set a property in a sub-task, but it not working. I put
> here a sample test:
> <target name="X">
>   <antcall target="Y" />
>    <echo message="Z is ${Z}" />
> </target>
> <target name="Y">
>   <property name="Z" value="OK" />
> </target>
> If I call the target X, I will get the output "Z is ${Z}" instead what I
> expect to happen, "Z is OK".
> How can I set a property in a sub-task if we know that properties are
> immutable?
> thanks,
> Pedro Salazar.
<id name="pedro salazar"> 

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

View raw message