使用 ANT 并面临问题
<target name="init">
<mkdir dir="${build.dir}" />
<if>
<available file="../war" type="dir"/>
<then></then>
<else>
<mkdir dir="../war" />
</else>
</if>
</target>
这是我用来检查文件夹是否存在的代码,但出现以下错误:
原因:名称未定义。
行动:检查拼写。
操作:检查是否已声明任何自定义任务/类型。
行动:检查是否已进行任何/声明。
我已将 ant-contrib.jar 复制到 ANT_HOME/lib 中。我哪里错了?
<target name="init">
<mkdir dir="${build.dir}" />
<if>
<available file="../war" type="dir"/>
<then></then>
<else>
<mkdir dir="../war" />
</else>
</if>
</target>
This is the code i am using to check if a folder exists, but getting the following error:
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
I have copied ant-contrib.jar in ANT_HOME/lib. where am i goin wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于上面的示例,您可以大大简化它:
...因为如果文件夹存在,
mkdir
任务不会执行任何操作(请参阅 文档)。如果您询问如何在 ant 中使用
if
和then
,我建议您选择另一个示例,因为 Ant 中的每个操作往往都有自己的内置条件。Given the example above, you can greatly simplify it:
...since the
mkdir
task does nothing if the folder exists (see documentation).If you're asking how to use
if
andthen
in ant, I recommend picking another example since each action in Ant tends to have its own conditionals built in.