Troubleshooting “failed to create task or type foreach” when using <foreach>

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

I'm trying to use the foreach loop in an Ant script but I get the message: Problem: failed to create task or type foreach Cause: The name is undefined.

I don't understand why this doesn't work. It is not a 3rd party library. It is a standard task that would be part of the latest version of Ant (1.8).

回答1:

It is a standard task that would be part of the latest version of Ant (1.8).

No, it's not. At least I can't find it in the list of core and optional tasks in the ant manual. It seems to be part of the ant-contrib project and thus needs to be installed separately.



回答2:

have you ever considered ? in this tag you can use some famous script language like javascript and python. they can also interact with the Project, Task... Object of Ant, which means you can set/get the properties and even excute another task. look at this example which comes from the book "java development with ant"

             Use a script task to generate a random number, then         print it       Random number is ${random}


回答3:

I can't find the foreach task in the Ant 1.8 manual - where is it? I only know the task from ant-contrib, and it requires to specify the 'target' attribute: http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html



回答4:

I had the same issue under eclipse with various versions of ant.

Add this into your code WITHOUT adding parameters under eclipse (do not specify any classpath) :



回答5:

You haven't defined a target to call:

alternatively:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!