排除ant build中的文件

时间:2014-11-03 14:24:20

标签: java ant

我有以下ant文件,

<project>
<path id="build-classpath">
    <fileset dir="/opt/apache-tomcat-7.0.53/lib">
        <include name="*.jar"/>
    </fileset>
    <fileset dir="../../lib">
       <include name="*.jar"/>
    </fileset>
    <fileset dir="../../bin">
       <include name="*.jar"/>
    </fileset>
</path>
<target name="compile">
  <mkdir dir="classes"/>
  <mkdir dir="bin"/>
  <javac srcdir="src/" destdir="classes" includeantruntime="false">
    <exclude name="/src/web/DaemonSocket.java"/>
    <classpath refid="build-classpath"/>
  </javac>
  <javac srcdir="src/" destdir="bin" includeantruntime="false">
    <classpath refid="build-classpath"/>
  </javac>
</target>
 <target name="clean">
    <delete dir="classes"/>
    <delete dir="bin"/>
  </target>
</project>

在包含代码的排除行

  <javac srcdir="src/" destdir="classes" includeantruntime="false">
    <exclude name="/src/web/DaemonSocket.java"/>
    <classpath refid="build-classpath"/>
  </javac>

我希望文件DaemonSocket.java不能编译到classes文件夹中。但是,每次运行ant compile时,DaemonSocket.java文件都会编译到classesbin文件夹中。为什么exclude在这种情况下不起作用?

1 个答案:

答案 0 :(得分:4)

尝试使用通配符:

  <javac srcdir="src/" destdir="classes" includeantruntime="false">
    <exclude name="**/DaemonSocket.java"/> <!--You should use relative path here /src/ should be removed if you dont want to use wildcard-->
    <classpath refid="build-classpath"/>
  </javac>