Java – Exclude jar from ant classpath

antclasspathjavamaven

I'm trying to make a "clean maven" setup on some legacy project that uses ant scripts. I don't know much about ant, so my question might seem naive.

I'm almost done, but the delivery ant script is failing, due to a redundancy in the classpath. If I understand the build, those lines should add to the classpath every lib in the "provided" scope :

<artifact:dependencies pathid="dependency.classpath" scopes="provided">
    <pom file="./pom.xml"/>
</artifact:dependencies>

And then this one :

<path id="completecp">
    <fileset dir="${ant.home}/lib">
        <include name="*.jar" />
    </fileset>
    <path refid="dependency.classpath" />
</path>

Add those dependencies to the libs in the ant.home directory.

The trouble is, I'm using a maven pom that is dependent on a parent pom that I can't modify, and as a result, there are THREE different versions of Ant in my classpath : two from the POM (1.5 et 1.7.1) and one from Eclipse (1.8.2). I've tried (desperately !) addind some maven exclusions, but failed miserably.

So I thought : maybe there is a way of excluding jars from the Ant classpath. I've tried putting :

<exclude name="*ant\1.7.1\ant-1.7.1.jar"/>
<exclude name="*ant\1.5\ant-1.5.jar"/>

in the fileset part, but it doesn't work. Is there a way of excluding those redundant jar ?

Best Answer

Try this way:-

<exclude name="**/ant/1.7.1/ant-1.7.1.jar"/>
<exclude name="**/ant/1.5/ant-1.5.jar"/>