java – 扩展现有的ant路径标记
发布时间:2020-12-15 02:15:25 所属栏目:Java 来源:网络整理
导读:是否可以扩展ant构建文件中的现有路径标记?例如,我想扩展: path id="project.classpath" pathelement path="build/classes" //path 使用新路径= module / lib.这样结果相当于: path id="project.classpath" pathelement path="build/classes" / patheleme
是否可以扩展ant构建文件中的现有路径标记?例如,我想扩展:
<path id="project.classpath"> <pathelement path="build/classes" /> </path> 使用新路径= module / lib.这样结果相当于: <path id="project.classpath"> <pathelement path="build/classes" /> <pathelement path="module/lib" /> </path> 解决方法
如果您尝试这样的方法,则无法直接扩展现有路径:
<path id="project.classpath"> <pathelement path="build/classes" /> </path> <path id="project.classpath"> <pathelement path="${ant.refid:project.classpath}" /> <pathelement path="module1/lib" /> </path> 由于您正在尝试读取并同时设置路径的“圆形”,它将失败. 您可以通过添加额外的步骤来打破圆圈,从而实现您想要的效果.在每次设置路径之前,将当前值存储在 <path id="cp"> <pathelement path="build/classes" /> </path> <echo message="${ant.refid:cp}" /> <string id="cps" value="${toString:cp}" /> <path id="cp"> <pathelement path="${ant.refid:cps}" /> <pathelement path="module1/lib" /> </path> <echo message="${ant.refid:cp}" /> <string id="cps" value="${toString:cp}" /> <path id="cp"> <pathelement path="${ant.refid:cps}" /> <pathelement path="module2/lib" /> </path> <echo message="${ant.refid:cp}" /> 运行时产生类似这样的东西: [echo] /ant/path/build/classes [echo] /ant/path/build/classes:/ant/path/module1/lib [echo] /ant/path/build/classes:/ant/path/module1/lib:/ant/path/module2/lib 您每次都将id重新分配给不同的路径.通常这是一个坏主意,因为您无法确定构建中每个点使用的路径:因此请小心使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |