首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在ant中排除javac任务中的源代码?

如何在ant中排除javac任务中的源代码?
EN

Stack Overflow用户
提问于 2010-06-30 09:44:28
回答 5查看 33.4K关注 0票数 17

我的build.xml中有以下内容:

代码语言:javascript
复制
<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‘属性“。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-06-30 13:29:33

一些人建议使用<exclude>。这不符合指定我的任务的方式。垃圾神的回答链接到了the sixth example on this page,它给了我一个关于如何重构我的任务规范的想法。

看起来我的问题与我指定源文件的方式有关。而不是在<src>中使用<pathelement>元素,如下所示:

代码语言:javascript
复制
<src>
   <pathelement location="${src.dir}/com/foo/bar/baz/" />
   <pathelement location="${src.dir}/com/foo/bar/quux/" />
</src>

我切换到使用带有路径的单个<src>,然后使用一组<include>元素,如下所示:

代码语言:javascript
复制
<src path="${src.dir}" />
<include name="com/foo/bar/baz/**" />
<include name="com/foo/bar/quux/**" />

这似乎在功能上是相同的,但与<exclude>的使用是兼容的

代码语言:javascript
复制
<exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>

(实际上,我很惊讶的是,最初的东西居然还能用。)

票数 18
EN

Stack Overflow用户

发布于 2010-06-30 11:31:51

其余的我不太确定,但是<exclude/>嵌套元素应该可以在Javac任务中工作。向下看第六个example

附录:中讨论了模式,包括**表示法。

代码语言:javascript
复制
<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>
票数 6
EN

Stack Overflow用户

发布于 2010-06-30 09:59:24

试一试

代码语言:javascript
复制
<javac>
(...>
<exclude name="${src.dir}/com/foo/bar/quux/dontwant/*" />
(...)
</javac>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3145968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档