next up previous contents index
Next: Jikes Notes Up: Javac Previous: Parameters specified as nested   Contents   Index

Examples

  
  <javac srcdir="${src}"
         destdir="${build}"
         classpath="xyz.jar"
         debug="on"
  />
compiles all .java files under the ${src} directory, and
stores the .class files in the $build directory. The classpath used includes xyz.jar, and compiling with debug information is on.
  
  <javac srcdir="${src}"
         destdir="${build}"
         fork="true"
  />
compiles all .java files under the ${src} directory, and
stores the .class files in the $build directory. This will fork off the javac compiler using the default javac executable.
  
  <javac srcdir="${src}"
         destdir="${build}"
         fork="java$$javac.exe"
  />
compiles all .java files under the ${src} directory, and
stores the .class files in the $build directory. This will fork off the javac compiler, using the executable named java $javac.exe. Note that the $ sign needs to be escaped by a second one.
  
  <javac srcdir="${src}"
         destdir="${build}"
         includes="mypackage/p1/**,mypackage/p2/**"
         excludes="mypackage/p1/testpackage/**"
         classpath="xyz.jar"
         debug="on"
  />
compiles .java files under the ${src} directory, and
stores the .class files in the $build directory. The classpath used includes xyz.jar, and debug information is on. Only files under mypackage/p1 and mypackage/p2 are used. All files in and below the mypackage/p1/testpackage directory are excluded from compilation.
  
  <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.


next up previous contents index
Next: Jikes Notes Up: Javac Previous: Parameters specified as nested   Contents   Index
Andrew Marlow 2003-07-08