Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant using antlib with namespace

I am using the following demonstration script:

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

When I run this build script (with target default), the error is

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

The pathelement lib/ant-contrib-1.0b3.jar exists, and ant is picking it up. I'm thinking the problem is how I'm using the xmlns. I'm taking this from another example that I have that also doesn't work for me (it works on a particular server, though!), and trying to figure out what the magic sauce is.

like image 693
lmat - Reinstate Monica Avatar asked Nov 29 '25 16:11

lmat - Reinstate Monica


1 Answers

Your taskdef where you're adding ant-contrib needs to declare a URI the same as the namespace you're defining and prefixing in the project. Similar to how the taskdef over here works.

<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>
like image 185
David Avatar answered Dec 02 '25 06:12

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!