There isn't antlib.xml in my ant-contrib-0.3

六眼飞鱼酱① 提交于 2019-11-28 11:41:38

问题


I am trying to use task for. I tried with this task definition:

    <taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="${infrastructure-base-dir}/apache-ant-1.9.6/lib/ant-contrib-0.3.jar"/>
        </classpath>
    </taskdef>

But didn't work. This message appear:

Problem: failed to create task or type for

So I decider to unzip ant-contrib-0.3.jar to see what's inside. And there wasn't antlib.xml in this path: net/sf/antcontrib/. So what would you advise me in order to make task FOR to work?


回答1:


Try this:

  1. In your build.xml

    <taskdef name="for-contrib" classname="net.sf.antcontrib.logic.ForTask" classpath="${basedir}/lib/ant-contrib-1.0b3.jar" />

  2. Place jar file file in correct location, i.e. in lib folder at same level as build.xml.

  3. Use the for as needed, i.e

    <for-contrib list="a,b,c,d,e" param="letter"> <sequential> <echo>Letter @{letter}</echo> </sequential> </for>

For task documentation




回答2:


The following build file will install Ant contrib automatically

<project name="ant-contrib-tasks" default="build">

    <available classname="net.sf.antcontrib.logic.ForTask" property="contrib.installed"/>

    <target name="install-contrib" unless="contrib.installed">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
        <fail message="Ant Contrib installed - Run Ant again"/>
    </target>

    <target name="build" depends="install-contrib">
      <taskdef resource="net/sf/antcontrib/antlib.xml"/>

        <for param="file">
            <fileset dir="." includes="*.txt"/>
            <sequential>
                <echo message="Found file @{file}"/>
            </sequential>
        </for>
    </target>

</project>


来源:https://stackoverflow.com/questions/34351322/there-isnt-antlib-xml-in-my-ant-contrib-0-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!