Ant:将文件集与javac任务一起使用 [英] Ant: Using a fileset with the javac task
问题描述
我想使用FileSet来确切指示我要使用Javac任务编译的文件.我不要任何隐式行为.但是,我对此的尝试失败了.这是到目前为止我得到的:
I want to use a FileSet to indicate exactly which files I want compiled with the Javac task. I don't want any implicit behavior. My attempts at this have failed however. Here's what I've got so far:
包含我所有源文件的FileSet.
A FileSet that contains all my source files.
<fileset id="srcfiles" dir="${srcdir}">
<include name="**/*.java"/>
</fileset>
还有一个尝试将其传递给javac的目标.
And a target that tries to pass it to javac.
<target name="build">
<javac srcdir=".">
<fileset refid="srcfiles"/>
</javac>
</target>
这给了我这个错误:javac doesn't support the nested "fileset" element.
在阅读Ant文档之后,我尝试将最里面的标签从fileset
更改为sourcepath
.从某种意义上说,这是可行的,因为文件已编译,但仍然出错:srcfiles doesn't denote a path
.我认为该源代码仅是根据隐式规则进行编译的.
After reading the Ant docs, I tried changing the inner most tag from fileset
to sourcepath
. This worked in the sense that the files were compiled, but it still errored out: srcfiles doesn't denote a path
. I think the source was only compiled due to implicit rules.
如何才能明确告诉javac我要编译哪些文件?还是这根本不是Ant应该如何工作的?我来自C ++背景,其中识别源文件是构建过程的重要组成部分.但是,考虑到Java的文件命名和目录结构要求,隐式**/*.java
模式规则可能涵盖所有用例.
How can I tell javac explicitly which individual files I want compiled? Or is this simply not how Ant is supposed to work? I come from a C++ background where identifying source files is a significant part of the build process. However, given Java's file naming and directory structure requirements, perhaps the implicit **/*.java
pattern rule covers all use cases.
推荐答案
ant手册对于Javac 说:
如果您只希望编译明确指定的文件并禁用 javac的默认搜索机制,则可以取消设置sourcepath 属性:
If you wish to compile only files explicitly specified and disable javac's default searching mechanism then you can unset the sourcepath attribute:
<javac sourcepath="" srcdir="${src}"
destdir="${build}" >
<include name="**/*.java"/>
<exclude name="**/Example.java"/>
</javac>
不过,我认为这不是一个好主意.在设计良好的项目中,应编译给定目录(或一组目录)中的所有文件.不应该编译的文件根本不应该存在,或者应该位于单独的目录中.
I don't think it's a good idea, though. In a well-designed project, all the files in a given directory (or in a set of directories) should be compiled. The files which shouldn't be compiled shouldn't be there at all, or should be in a separate directory.
这篇关于Ant:将文件集与javac任务一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!