2

我正在使用以下演示脚本:

<?xml version="1.0" encoding="UTF-8"?>
<project name="test" basedir="." xmlns:deploy="antlib:net.sf.antcontrib">
    <target name="default">
        <taskdef resource="net/sf/antcontrib/antlib.xml">
            <classpath>
                <pathelement location="lib/ant-contrib-1.0b3.jar"/>
            </classpath>
        </taskdef>
        <deploy:if>
            <isset property="defaultprop"/>
            <then>
                <echo message="it's set!"/>
            </then>
        </deploy:if>
    </target>
</project>

当我运行此构建脚本(使用 target default)时,错误是

build.xml:9: Problem: failed to create task or type antlib:net.sf.antcontrib:if

pathelementlib/ant-contrib-1.0b3.jar存在,而 ant 正在拾取它。我在想问题是我如何使用 xmlns。我从另一个对我也不起作用的例子中得到这个(不过,它适用于特定的服务器!),并试图弄清楚魔法酱是什么。

4

2 回答 2

9

添加 ant-contrib 的 taskdef 需要声明一个与您在项目中定义和前缀的名称空间相同的 URI。类似于此处的 taskdef 的工作方式。

<project name="test" basedir="." xmlns:deploy="antlib:net.sf.antcontrib">
    <target name="default">
        <taskdef uri="antlib:net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml">
            <classpath>
                <pathelement location="lib/ant-contrib-1.0b3.jar"/>
            </classpath>
        </taskdef>
        <deploy:if>
            <isset property="defaultprop"/>
            <then>
                <echo message="it's set!"/>
            </then>
        </deploy:if>
    </target>
</project>
于 2013-02-28T17:16:12.867 回答
0

好吧,错误if在最后,它在谈论第9行。我认为这是这个标签的语法有问题:

    <deploy:if>

我在“deploy:if”标签甚至“deploy”标签上找不到任何文档。我认为 Ant 中没有“部署”任务 - 你需要创建一个“部署”目标

试试这个怎么样:

  <if>
    <isset property="defaultprop"/>
    <then>
      <antcall target="deploy" />
    </then>
  </if>

当我阅读它时,这将检查 isset,然后调用“部署”目标(如果已设置)。当然,您现在需要制定“部署”目标 :)

于 2013-02-28T17:08:22.763 回答