jgr208
jgr208

Reputation: 3066

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?

Upvotes: 1

Views: 13481

Answers (1)

SMA
SMA

Reputation: 37023

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>

Upvotes: 5

Related Questions