问题描述
在一个项目中,我们有多个源路径,因此我们为它们定义了一个引用路径:
In a project we have several source paths, so we defined a reference path for them:
<path id="de.his.path.srcpath">
<pathelement path="${de.his.dir.src.qis.java}"/>
<pathelement path="${de.his.dir.src.h1.java}"/>
...
</path>
在 <javac> 中使用参考工作正常.标签:
Using the reference works fine in the <javac> tag:
<src refid="de.his.path.srcpath" />
下一步,我们必须将非java文件复制到classpath文件夹中:
In the next step, we have to copy non-java files to the classpath folder:
<copy todir="${de.his.dir.bin.classes}" overwrite="true">
<fileset refid="de.his.path.srcpath">
<exclude name="**/*.java" />
</fileset>
</copy>
不幸的是,这行不通,因为refid"和嵌套元素可能不会混合在一起.
Unfortunately, this does not work because "refid" and nested elements may not be mixed.
有没有一种方法可以在我的源路径中获取一组所有非 java 文件,而无需将源路径列表复制到单个文件集中?
Is there a way I can get a set of all non-java files in my source path without copying the list of source paths into individual filesets?
推荐答案
这是一个选项.首先,使用 pathconvert 任务制作适合生成文件集的模式:
Here's an option. First, use the pathconvert task to make a pattern suitable for generating a fileset:
<pathconvert pathsep="/**/*,"
refid="de.his.path.srcpath"
property="my_fileset_pattern">
<filtermapper>
<replacestring from="${basedir}/" to="" />
</filtermapper>
</pathconvert>
接下来从路径中的所有文件创建文件集,java 源除外.注意尾随通配符 /**/*
需要,因为 pathconvert 只处理列表中的通配符,而不是最后需要的通配符:
Next make the fileset from all the files in the paths, except the java sources. Note the trailing wildcard /**/*
needed as pathconvert only does the wildcards within the list, not the one needed at the end:
<fileset dir="." id="my_fileset" includes="${my_fileset_pattern}/**/*" >
<exclude name="**/*.java" />
</fileset>
那么您的复制任务将是:
Then your copy task would be:
<copy todir="${de.his.dir.bin.classes}" overwrite="true" >
<fileset refid="my_fileset" />
</copy>
为了可移植性,您可以考虑使用以下内容,而不是硬编码 unix 通配符 /**/*
:
For portability, instead of hard-coding the unix wildcard /**/*
you might consider using something like:
<property name="wildcard" value="${file.separator}**${file.separator}*" />
这篇关于如何从 Ant 中的引用路径中排除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!