Given the directory structure mentioned in your question, it sounds like all of your non-test code is in the directory bb/app/lite2
. In that case, you could write the <copy>
task as follows as long as bb/app/lite2
appears below the specified source directory:
<property name="source.dir" location="${basedir}/src" />
<property name="target.dir" location="${basedir}/target" />
<copy todir="${target.dir}" overwrite="true">
<fileset dir="${source.dir}" includes="bb/app/lite2/**/*.java" />
</copy>
However, adopting a naming convention for your test files such as <ClassName>Test.java
makes it possible to write includes/excludes patterns as follows.
Copy all sources excluding tests
<property name="source.dir" location="${basedir}/src" />
<property name="target.dir" location="${basedir}/target" />
<copy todir="${target.dir}" overwrite="true">
<fileset dir="${source.dir}"
includes="**/*.java" excludes="**/*Test.java" />
</copy>
The <javac>
Ant task supports includes
and excludes
attributes, so rather than copy source files to a new directory, you can select the non-test files directly.
Use <javac>
Ant task includes
and excludes
attributes
<property name="source.dir" location="${basedir}/src" />
<property name="classes.dir" location="${basedir}/build/classes" />
<javac srcdir="${source.dir}" destdir="${classes.dir}"
includes="**/*.java" excludes="**/*Test.java"
classpathref="my.classpath" debug="on" deprecation="on" />
As David W. mentioned in his comment, another convention (that may used in conjunction with a file naming convention) is to place test code in a separate directory. For example,
Or following the maven convention:
src/main/java
src/test/java
Then compiling your non-test sources is simple since you do not have to specify includes/excludes patterns:
<property name="source.dir" location="${basedir}/src/java" />
<property name="classes.dir" location="${basedir}/build/classes" />
<javac srcdir="${source.dir}" destdir="${classes.dir}"
classpathref="my.classpath" debug="on" deprecation="on" />
Related stackoverflow questions