I am encountering the following error when I try to use Ant-contrib's FOR loop:
Invalid type class org.apache.tools.ant.taskdefs.optional.script.ScriptDefBase used in For task, it does not have a public iterator method
My code is as follows:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="WTemplateNewIshopForm/jar/ant-contrib-1.0b2.jar"/>
</classpath>
</taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="WTemplateNewIshopForm/jar/ant-contrib-1.0b2.jar"/>
</classpath>
</taskdef>
<scriptdef language="javascript" name="upstring">
<attribute name="string" />
<attribute name="to" />
<![CDATA[
var the_string = attributes.get( "string" );
project.setProperty(
attributes.get( "to" ),
the_string.toUpperCase() );
]]>
</scriptdef>
<property name="mulSvcTypes" value="TEST01;TEST02;TEST03;" />
<for list="${mulSvcTypes}" delimiter=";" param="mulSvcType">
<upstring string="${mulSvcType}" to="mulSvcTypeuc" />
<sql
driver="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2://test.test" userid="test" password="test">
<classpath>
<pathelement path="WTemplateNewIshopForm/jar/db2jcc.jar:WTemplateNewIshopForm/jar/db2jcc_license_cisuz.jar:WTemplateNewIshopForm/jar/db2jcc_license_cu.jar"/>
</classpath>
<![CDATA[
INSERT INTO TEST.GRP VALUES ('${mulSvcTypeuc}', '${groupdb}', 'Y');
]]>
<![CDATA[
INSERT INTO TEST.APRV VALUES ('${mulSvcTypeuc}', '${approver}');
]]>
</sql>
</for>
What does the error mean? Thank you
The
for
task supports iterating over nested elements such as lists, filesets or anything with aniterator()
method. It also supports iterating over both thelist
attribute AND nested elements, if both are given. The task to actually repeat (i.e. the "body" of the for loop) needs to be inside asequential
element.The error means your first inner task is being treated as something to iterate over instead of the body of the loop like you want. Since it doesn't have an
iterator()
method, it's throwing an error.To fix this, try surrounding your two inner tasks with a
sequential
task.See http://ant-contrib.sourceforge.net/tasks/tasks/for.html for further information.