4

I've got a strange problem with ant. It's version is 1.7.1.

I'm trying to do next thing and get the error.

<target name="execute-all-buildfiles">
    <foreach param="buildfile-path" target="execute-buildfile">
        <path>
            <dirset dir="${path.to.server}/share/source"/>
        </path>
    </foreach>
</target>

<target name="execute-buildfile">
    <echo message="" />
    <echo message="" />
    <echo message="" />
    <echo message="__________ Building cartridge ${buildfile-path} ___________" />
    <echo message="" />
    <echo message="" />
    <echo message="" />
    <java
            jvm="${path.to.server}/engine/jdk/bin/java"
            classname="org.apache.tools.ant.launch.Launcher"
            fork="true"
            failonerror="true">
        <classpath>
            <pathelement location="${ant.home}/lib/ant-launcher.jar"/>
        </classpath>
        <arg value="-f" />
        <arg value="${buildfile-path}/build/build.xml" />
        <arg value="-Dis.home=${path.to.server}" />
    </java>
</target>

I've tried less complicated version of foreach, but it doesn't work as well. Please, help me.

<target name="run">     
   <foreach target="loop" param="loop.param">  
      <path>
          <dirset dir="${path.to.server}/share/source"/>
      </path>
   </foreach>  
</target>  
<target name="loop">     
   <echo message="${loop.param}"/>  
   <basename property="dir.name" file="${loop.param}"/>  
   <echo message="${dir.name}"/>  
</target>  

P.S. Sorry for mistakes. Take a look at a simple one.

Selik
  • 71
  • 1
  • 1
  • 10
  • Is missing "<" before target is a typo while posting question? – Pradeep Simha Mar 11 '13 at 17:28
  • Could you post the "less complicated version of foreach" as a quasi-[SSCCE](http://www.sscce.org)? – wchargin Mar 11 '13 at 17:32
  • Also, don't you have to have either a `list=a,b,c,d` attribute or a nested `fileset`? I only see a `dirset`, maybe it doesn't like that. – wchargin Mar 11 '13 at 17:34
  • I've tried on the other machine, and second target run successfully. What can cause it, my brain already hurts – Selik Mar 11 '13 at 17:39
  • See: http://stackoverflow.com/questions/15304845/getting-an-error-could-not-load-definitions-from-resource-net-sf-antcontrib-ant/15308399#15308399 – Mark O'Connor Mar 11 '13 at 22:13

1 Answers1

15

"Cause: The name is undefined" means the task is not installed in your ant environment.
<foreach> is not a task of vanilla ant but needs the ant addon antcontrib available for ant.
After installing antcontrib you should use <taskdef resource="net/sf/antcontrib/antlib.xml"/> to activate all antcontrib tasks.
GOTCHA => Don't use <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> as mentioned on http://ant-contrib.sourceforge.net/ as net/sf/antcontrib/antcontrib.properties contains only tasks for ant versions before Ant 1.6.x

Rebse
  • 10,307
  • 2
  • 38
  • 66