Given the directory structure pointed out in your question, it looks like all your non-test code is in the bb/app/lite2 . In this case, you can write the <copy> task as follows until bb/app/lite2 appears under 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, accepting a naming convention for your test files, such as <ClassName>Test.java , allows you 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 the includes and excludes , so instead of copying the source files to a new one, you can directly select non-test files.
Use the <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" />
Like David W. , mentioned in his commentary, another convention (which can be used in conjunction with a file naming convention) is to place the test code in a separate directory. For instance,
Or after the maven convention:
src/main/javasrc/test/java
Then compiling your non-test sources is simple, since you do not need to specify include / exclude 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" />
Stackoverflow Related Questions