In Ant, how to specify the source code to be compiled
I开发者_StackOverflow am using an Ant script for building Java project. In the source code file, src, I have two files, test1.java, test2.java and test3.java. At present, I only want to compile test1.java and test2.java.
My ant script has sth like
<property name="src" location="./src"/>
<javac srcdir="${src}" destdir="${build}" classpathref="classpath"/>
This script essentially compiles all three java file. How to modify the above one, in specific, to leave test3.java away.
You can simply add a nested exclude
element in the javac
task.
<javac srcdir="${src}" destdir="${build}" classpathref="classpath">
<exclude name="**/test3.java">
</javac>
See here for example about how to use nested include
and exclude
elements to control the files that are built.
There are plenty of examples in the ant docs (look under tasks/javac). E.g.
<javac sourcepath="" srcdir="${src}"
destdir="${build}" >
<include name="**/*.java"/>
<exclude name="**/Example.java"/>
</javac>
But unless this is a throwaway example, excluding one class isn't such a great idea - e.g. you might have code in test2 that depends on test3 - this would then work properly in an ide but break in your ant script.
精彩评论