如何在 ant 的 javac 任务中排除源? [英] How can I exclude sources in a javac task in ant?

查看:38
本文介绍了如何在 ant 的 javac 任务中排除源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following in my 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/ 要在此任务中编译).

This mostly does what I want, except that (as the comment says) I do not want the files in
${src.dir}/com/foo/bar/quux/dontwant/ to be compiled by this task (but I do want everything else under ${src.dir}/com/foo/bar/quux/ to be compiled in this task).

我是一个完整的蚂蚁 n00b,文档对我帮助不大.我看到几个地方说有各种排除/排除元素/属性,但我能想到的每个变化要么没有效果,要么导致错误,如blah不支持'排除'属性".

I'm a complete ant n00b, and the documentation hasn't been much help to me. I see several places where it says there are various exclude/excludes elements/attributes, but every variation I can think of either has no effect or results in an error like "blah doesn't support the 'exclude' attribute".

推荐答案

一些人建议使用 .这不符合我的任务指定方式.垃圾神的回答链接到 本页上的第六个例子,这让我知道如何重组我的任务规范.

A couple of people suggested using <exclude>. This didn't work with the way my task was specified. trashgod's answer linked to the sixth example on this page which gave me an idea of how to restructure my task specification.

看起来我的问题与我指定源文件的方式有关.而不是在 中使用 元素,像这样:

It looks like my problem was related to the way I was specifying the source files. Rather than using <pathelement> elements in a <src>, like this:

<src>
   <pathelement location="${src.dir}/com/foo/bar/baz/" />
   <pathelement location="${src.dir}/com/foo/bar/quux/" />
</src>

我切换到使用单个 和一个路径,然后使用一组 元素,如下所示:

I switched to using a single <src> with a path and then a set of <include> elements, like this:

<src path="${src.dir}" />
<include name="com/foo/bar/baz/**" />
<include name="com/foo/bar/quux/**" />

这看起来在功能上是相同的,但与 的使用兼容:

This appears to be functionally identical, but is compatible with the use of <exclude>:

<exclude name="${src.dir}/com/foo/bar/quux/dontwant/**"/>

(实际上,我很惊讶最初存在的东西竟然有效.)

(Actually, I'm surprised that what was there in the first place worked at all.)

这篇关于如何在 ant 的 javac 任务中排除源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆