Extending the answer provided by @user4386022: You can define (starting with Ant 1.8) this macro which can help you if you have the same problem in different places in your build process (and you cannot just copy-paste the same snippet everywhere because Ant does not allow re-defining properties, so you will get an error saying that "manifest.classpath" is already defined.)
<macrodef name="create-classpath-jar" description="Create classpath Jar, to avoid getting the error about CreateProcess error=206, The filename or extension is too long">
<attribute name="classpathjar"/>
<attribute name="classpathref"/>
<sequential>
<!-- Turn the classpath into a property formatted for inclusion in a MANIFEST.MF file -->
<local name="manifest.classpath.property"/>
<manifestclasspath property="manifest.classpath.property" jarfile="@{classpathjar}">
<classpath refid="@{classpathref}" />
</manifestclasspath>
<!-- Create the Jar -->
<jar destfile="@{classpathjar}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath.property}"/>
</manifest>
</jar>
</sequential>
</macrodef>
To use the macro in your targets or tasks, then simply use it like this:
<path id="myclasspath">
.........
</path>
<create-classpath-jar classpathjar="classpath-compile.jar" classpathref="myclasspath" />