java Ant foreach:原因:名称未定义。但似乎一切正常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15344792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant foreach: Cause: The name is undefined. But everything seems to be ok
提问by Selik
I've got a strange problem with ant. It's version is 1.7.1.
我对蚂蚁有一个奇怪的问题。它的版本是 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.
我尝试过不那么复杂的 foreach 版本,但效果不佳。请帮我。
<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.
PS抱歉错误。看一个简单的。
回答by Rebse
"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 antcontribavailable 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
“原因:名称未定义”表示该任务未安装在您的 ant 环境中。<foreach>
不是 vanilla ant 的任务,但需要 ant 插件antcontrib可用于 ant。
安装 antcontrib 后,您应该使用它<taskdef resource="net/sf/antcontrib/antlib.xml"/>
来激活所有 antcontrib 任务。
GOTCHA=> 不要<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
像http://ant-contrib.sourceforge.net/ 上提到的那样使用,因为 net/sf/antcontrib/antcontrib.properties 只包含 Ant 1.6.x 之前的 ant 版本的任务