一、概述
manifestclasspath是Ant1.7引入的任务,用于将path转换为适合于manifest的class-path属性。当启动程序使用非常长的路径时,这个任务通常用于解决windows上的命令行限制。通常在命令行上指定的长类路径被一个单一的列出了所有classpath应包含的jar和zip文件的class-path属性的jar文件所取代。所创建的属性值可能比每行的清单的最大72个字符长,但用<manifest>元素按Jar规范正确地包装,其中定义的属性被重新引用。
二、属性
property:要设置的属性的名称,属性必须没有被设置过。
jarfile:包含使用此任务将设置的属性的清单的jar文件名,文件的父目录必须存在。
maxParentLevels:允许遍历的最大父目录数,以便从jar文件导航到路径条目,也就是从jarfile指定的文件到给定类路径的相对路径中允许的最大的“..”数目,若设置为0表示jar文件与路径条目在相同目录,默认为2。
三、简单示例
<project >
<path id="classpath">
<fileset dir="../../../Program Files/apache-ant-1.8.4/lib">
<include name="*.jar" />
</fileset>
</path>
<manifestclasspath property="jar.classpath" jarfile="acme.jar" maxparentlevels="3">
<classpath refid="classpath"/>
</manifestclasspath>
<manifest file="MANIFEST.MF">
<attribute name="Built-By" value="runner"/>
<section name="common">
<attribute name="Specification-Title" value="Example"/>
<attribute name="Specification-Version" value="1.0.0"/>
<attribute name="Specification-Vendor" value="Example Organization"/>
<attribute name="Implementation-Title" value="common"/>
<attribute name="Implementation-Version" value="1.0.0 "/>
<attribute name="Implementation-Vendor" value="Example Corp."/>
</section>
<section name="common/class1.class">
<attribute name="Sealed" value="false"/>
</section>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</project>
本文介绍了Ant 1.7中新增的manifestclasspath任务,该任务用于将长路径转换为适用于manifest的Class-Path属性,解决Windows命令行限制问题。文章通过示例展示了如何配置并使用该任务。

2197

被折叠的 条评论
为什么被折叠?



