0

我的 Ant 的 lib 文件夹中有 antcontrib.jar。我将我的 ant home 设置为“C/Prog Files/apache-ant”。

但是当我运行 build.xml 时,我仍然收到警告“无法加载 antlib.xml 和 antcontrib.prop”。

因此,我无法执行任何“正则表达式”操作。

我在ant的lib文件夹中正确加载了antcontrib.jar。

我在这里错在哪里?

4

2 回答 2

1

提供resourceclasspath在您的taskdef正确如下

<typedef resource="net/sf/antcontrib/antlib.xml" classpath="<path to ant-contrib.jar>"/> 
于 2013-05-13T08:55:45.787 回答
0

下面是一个使用 Ant-Contrib<propertyregex>任务的 Ant 脚本示例:

构建.xml

<project name="ant-propregex-simple" default="run">
    <taskdef resource="net/sf/antcontrib/antlib.xml" />
    <target name="run">
        <property name="line.to.test" value="First Second" />
        <property name="the.regex" value="^([^ ]*) ([^ ]*)$" />
        <propertyregex 
            input="${line.to.test}" 
            regexp="${the.regex}" 
            select="\2" 
            property="the.match" 
        />
        <echo>${the.match}</echo>
    </target>
</project>

关键是<taskdef ...>线。

输出

run:
     [echo] Second

BUILD SUCCESSFUL
于 2013-05-13T15:12:16.520 回答