gpt4 book ai didi

java - Ant 使用带有命名空间的 antlib

转载 作者:行者123 更新时间:2023-11-29 10:03:42 24 4
gpt4 key购买 nike

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

<?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>

当我运行这个构建脚本(使用目标 default)时,错误是

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

路径元素 lib/ant-contrib-1.0b3.jar 存在,ant 正在拾取它。我在想问题是我如何使用 xmlns。我从另一个对我也不起作用的例子(尽管它在特定的服务器上工作!),并试图找出神奇的酱料是什么。

最佳答案

您要在其中添加 ant-contrib 的任务定义需要声明一个与您在项目中定义和添加前缀的命名空间相同的 URI。类似于 taskdef over here 的方式有效。

<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>

关于java - Ant 使用带有命名空间的 antlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15141285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com