您可以定义通配符和模式匹配以在构建中包含/排除各种文件和文件夹。查看Ant 手册,了解文件集之类的内容如何与包含和排除过滤器一起使用。
另外,阅读教程。
这是一个简单的构建文件,它可以编译所有 java 文件并引用所有 jar。将其放在顶级目录中:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" 
    href="http://www.ibm.com/developerworks/xml/library/x-antxsl/examples/example2/ant2html.xsl"?>
<project name="Proj Name" default="build" basedir=".">
    <property name="src.dir" value="${basedir}" description="base folder where the source files will be found.  Typically under /src, but could be anywhere.  Defaulting to root directory of the project" />
    <property name="build.dir" value="build" description="Where to put build files, separate from src and resource files." />
    <path id="master-classpath">
        <fileset dir="${basedir}" description="looks for any jar file under the root directory">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <target name="build" description="Compile all JAVA files in the project">
        <javac srcdir="${src.dir}" 
            destdir="${build.dir}/classes" 
            debug="true" 
            deprecation="true" 
            verbose="false" 
            optimize="false"  
            failonerror="true">
            <!--master-classpath is defined above to include any jar files in the project subdirectories(can  be customized to include/exclude)-->
            <classpath refid="master-classpath"/>
            <!--If you want to define a pattern of files/folders to exclude from compilation...-->
            <exclude name="**/realm/**"/>
        </javac>  
    </target>
</project>