<javac srcdir="${src}" destdir="${build}" classpath="xyz.jar" debug="on" />compiles all .java files under the
<javac srcdir="${src}" destdir="${build}" fork="true" />compiles all .java files under the
<javac srcdir="${src}" destdir="${build}" fork="java$$javac.exe" />compiles all .java files under the
<javac srcdir="${src}" destdir="${build}" includes="mypackage/p1/**,mypackage/p2/**" excludes="mypackage/p1/testpackage/**" classpath="xyz.jar" debug="on" />compiles .java files under the
<javac srcdir="${src}:${src2}" destdir="${build}" includes="mypackage/p1/**,mypackage/p2/**" excludes="mypackage/p1/testpackage/**" classpath="xyz.jar" debug="on" />is the same as the previous example, with the addition of a second source path, defined by the property src2. This can also be represented using nested <src> elements as follows:
<javac destdir="${build}" classpath="xyz.jar" debug="on"> <src path="${src}"/> <src path="${src2}"/> <include name="mypackage/p1/**"/> <include name="mypackage/p2/**"/> <exclude name="mypackage/p1/testpackage/**"/> </javac>If you want to run the javac compiler of a different JDK, you should tell Ant, where to find the compiler and which version of JDK you will be using so it can choose the correct command line switches. The following example executes a JDK 1.1 javac in a new process and uses the correct command line switches even when Ant is running in a Java VM of a different version:
<javac srcdir="${src}" destdir="${build}" fork="yes" executable="/opt/java/jdk1.1/bin/javac" compiler="javac1.1" />Note: If you wish to compile only source files located in certain packages below a common root, use the include/exclude attributes or <include>/<exclude> nested elements to filter for these packages. Do not include part of your package structure in the srcdir attribute (or nested <src> elements), or Ant will recompile your source files every time you run your compile target. See the Ant FAQ for additional information.
Note: If you are using Ant on Windows and a new DOS window pops up for every use of an external compiler, this may be a problem of the JDK you are using. This problem may occur with all JDKs < 1.2.