简体   繁体   中英

Exclude files in ant build

I have the following ant file,

<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>

At the exclude line with the code,

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

I expect the file DaemonSocket.java not to be compiled into the classes folder. However everytime I run ant compile , the DaemonSocket.java file is compiled into both the classes and the bin folder. Why might the exclude not be working in this case?

Try wildcard:

  <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM