使用 ANT 并面临问题

发布于 2025-01-05 02:15:16 字数 492 浏览 2 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2025-01-12 02:15:16

鉴于上面的示例,您可以大大简化它:

<target name="init">
    <mkdir dir="${build.dir}" />
    <mkdir dir="../war" />
</target>

...因为如果文件夹存在,mkdir 任务不会执行任何操作(请参阅 文档)。

如果您询问如何在 ant 中使用 ifthen,我建议您选择另一个示例,因为 Ant 中的每个操作往往都有自己的内置条件。

Given the example above, you can greatly simplify it:

<target name="init">
    <mkdir dir="${build.dir}" />
    <mkdir dir="../war" />
</target>

...since the mkdir task does nothing if the folder exists (see documentation).

If you're asking how to use if and then in ant, I recommend picking another example since each action in Ant tends to have its own conditionals built in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文