扩展@user4386022 提供的答案:您可以定义(从 Ant 1.8 开始)这个宏,如果您在构建过程中的不同位置遇到相同的问题,它可以为您提供帮助(并且您不能只是复制粘贴相同的片段,因为 Ant不允许重新定义属性,因此您将收到一条错误消息,指出“manifest.classpath”已定义。)
<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>
要在目标或任务中使用宏,只需像这样使用它:
<path id="myclasspath">
.........
</path>
<create-classpath-jar classpathjar="classpath-compile.jar" classpathref="myclasspath" />