我的build.xml中有以下内容:
<target name="compile.baz" depends="init">
<javac destdir="${build.dir}/classes" debug="on">
<compilerarg value="-Xlint:deprecation"/>
<src>
<pathelement location="${src.dir}/com/foo/bar/baz/" />
<pathelement location="${src.dir}/com/foo/bar/quux/" />
<!-- Need to exclude ${src.dir}/com/foo/bar/quux/dontwant/ -->
</src>
<classpath refid="classpath.jars" />
</javac>
...
</target>
这基本上就是我想要的,除了(正如评论所说的)我不想把文件放在
此任务将编译${src.dir}/com/foo/bar/quux/dontwant/
(但我确实希望在此任务中编译${src.dir}/com/foo/bar/quux/
下的所有其他内容)。
我看到有几个地方说有各种各样的exclude/excludes元素/属性,但我能想到的每一种变化要么没有效果,要么导致错误,比如"blah不支持'exclude‘属性“。
发布于 2010-06-30 13:29:33
一些人建议使用<exclude>
。这不符合指定我的任务的方式。垃圾神的回答链接到了the sixth example on this page,它给了我一个关于如何重构我的任务规范的想法。
看起来我的问题与我指定源文件的方式有关。而不是在<src>
中使用<pathelement>
元素,如下所示:
<src>
<pathelement location="${src.dir}/com/foo/bar/baz/" />
<pathelement location="${src.dir}/com/foo/bar/quux/" />
</src>
我切换到使用带有路径的单个<src>
,然后使用一组<include>
元素,如下所示:
<src path="${src.dir}" />
<include name="com/foo/bar/baz/**" />
<include name="com/foo/bar/quux/**" />
这似乎在功能上是相同的,但与<exclude>
的使用是兼容的
<exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>
(实际上,我很惊讶的是,最初的东西居然还能用。)
发布于 2010-06-30 11:31:51
其余的我不太确定,但是<exclude/>
嵌套元素应该可以在Javac
任务中工作。向下看第六个example。
附录:中讨论了模式,包括**
表示法。
<target name="compile.baz" depends="init">
<javac destdir="${build.dir}/classes" debug="on">
<compilerarg value="-Xlint:deprecation"/>
<src>
<pathelement location="${src.dir}/com/foo/bar/baz/" />
<pathelement location="${src.dir}/com/foo/bar/quux/" />
</src>
<exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>
...
</javac>
...
</target>
发布于 2010-06-30 09:59:24
试一试
<javac>
(...>
<exclude name="${src.dir}/com/foo/bar/quux/dontwant/*" />
(...)
</javac>
https://stackoverflow.com/questions/3145968
复制相似问题