我正在尝试让ant4eclipse正常工作,我也用过一些ant,但并不比简单的脚本语言高出多少。我们在Eclipse项目中有多个源文件夹,因此ant4eclipse文档中的示例需要进行调整:
目前我有以下内容:
<target name="build">
<!-- resolve the eclipse output location -->
<getOutputpath property="classes.dir" workspace="${workspace}" projectName="${project.name}" />
<!-- init output location -->
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}" />
<!-- resolve the eclipse source location -->
<getSourcepath pathId="source.path" project="." allowMultipleFolders='true'/>
<!-- read the eclipse classpath -->
<getEclipseClasspath pathId="build.classpath"
workspace="${workspace}" projectName="${project.name}" />
<!-- compile -->
<javac destdir="${classes.dir}" classpathref="build.classpath" verbose="false" encoding="iso-8859-1">
<src refid="source.path" />
</javac>
<!-- copy resources from src to bin -->
<copy todir="${classes.dir}" preservelastmodified="true">
<fileset refid="source.path">
<include name="**/*"/>
<!--
patternset refid="not.java.files"/>
-->
</fileset>
</copy>
</target>任务运行成功,但我无法让工作-它应该复制所有的非java文件,以模仿eclipse的行为。
因此,我有一个名为source.path的pathId,其中包含多个目录,我需要以某种方式将其转换为复制任务所需的内容。我已经尝试了无效的嵌套,以及其他一些胡乱猜测。
我该怎么做呢--提前谢谢。
发布于 2009-03-26 12:22:34
您可以使用ant-contrib库中的foreach任务:
<target name="build">
...
<!-- copy resources from src to bin -->
<foreach target="copy.resources" param="resource.dir">
<path refid="source.path"/>
</foreach>
</target>
<target name="copy.resources">
<copy todir="${classes.dir}" preservelastmodified="true">
<fileset dir="${resource.dir}" exclude="**/*.java">
</copy>
</target>如果您的source.path也包含文件路径,那么您可以使用if任务(也来自ant-contrib)来防止试图复制文件路径的文件,例如
<target name="copy.resources">
<if>
<available file="${classes.dir}" type="dir"/>
<then>
<copy todir="${classes.dir}" preservelastmodified="true">
<fileset dir="${resource.dir}" exclude="**/*.java">
</copy>
</then>
</if>
</target>发布于 2010-10-04 05:31:41
您可以考虑使用pathconvert来构建fileset includes可以使用的模式。
<pathconvert pathsep="/**/*," refid="source.path" property="my_fileset_pattern">
<filtermapper>
<replacestring from="${basedir}/" to="" />
</filtermapper>
</pathconvert>它将用如下所示的字符串填充${my_fileset_pattern}:
1/**/*,2/**/*,3如果source.path由basedir下的3个目录1、2和3组成。我们使用pathsep插入通配符,这些通配符稍后将扩展到整个文件集。
现在可以使用该属性生成所有文件的文件集。请注意,需要一个额外的尾随/**/*来展开集合中的最后一个目录。此时可以应用排除。
<fileset dir="." id="my_fileset" includes="${my_fileset_pattern}/**/*">
<exclude name="**/*.java" />
</fileset>然后,所有非java文件的副本变为:
<copy todir="${classes.dir}" preservelastmodified="true">
<fileset refid="my_fileset" />
</copy>这将在保留todir下的源目录结构的基础上复制源文件。如果需要,可以设置复制任务的flatten属性,使所有源文件直接复制到todir。
请注意,这里的路径转换示例是针对unix文件系统的,而不是针对windows的。如果需要一些可移植的东西,那么应该使用file.separator属性来构建模式:
<property name="wildcard" value="${file.separator}**${file.separator}*" />
<pathconvert pathsep="${wildcard}," refid="source.path" property="my_fileset">
...https://stackoverflow.com/questions/685237
复制相似问题