2001-02-13 12:32:01 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
|
|
|
<title>Ant User Manual</title>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2><a name="javac">Javac</a></h2>
|
|
|
|
<h3>Description</h3>
|
|
|
|
<p>Compiles a source tree within the running (Ant) VM.</p>
|
|
|
|
<p>The source and destination directory will be recursively scanned for Java
|
|
|
|
source files to compile. Only Java files that have no corresponding class file
|
|
|
|
or where the class file is older than the java file will be compiled.</p>
|
2001-04-26 23:31:43 +00:00
|
|
|
<p>Note: Ant uses only the names of the source and class files to find
|
|
|
|
the classes that need a rebuild. It will not scan the source and therefor
|
|
|
|
will have no knowledge about nested classes, classes that are named different
|
|
|
|
from the source file and so on.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<p>The directory structure of the source tree should follow the package
|
|
|
|
hierarchy.</p>
|
|
|
|
<p>It is possible to refine the set of files that are being compiled/copied.
|
|
|
|
This can be done with the <i>includes</i>, <i>includesfile</i>, <i>excludes</i>, <i>excludesfile</i> and <i>defaultexcludes</i>
|
|
|
|
attributes. With the <i>includes</i> or <i>includesfile</i> attribute you specify the files you want to
|
|
|
|
have included by using patterns. The <i>exclude</i> or <i>excludesfile</i> attribute is used to specify
|
|
|
|
the files you want to have excluded. This is also done with patterns. And
|
|
|
|
finally with the <i>defaultexcludes</i> attribute, you can specify whether you
|
|
|
|
want to use default exclusions or not. See the section on <a
|
|
|
|
href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on how the
|
|
|
|
inclusion/exclusion of files works, and how to write patterns.</p>
|
|
|
|
<p>It is possible to use different compilers. This can be selected with the
|
|
|
|
"build.compiler" property. There are four choices:</p>
|
|
|
|
<ul>
|
|
|
|
<li>classic (the standard compiler of JDK 1.1/1.2)</li>
|
|
|
|
<li>modern (the new compiler of JDK 1.3)</li>
|
|
|
|
<li>jikes (the <a
|
|
|
|
href="http://oss.software.ibm.com/developerworks/opensource/jikes/project" target="_top">Jikes</a>
|
|
|
|
compiler)</li>
|
|
|
|
<li>jvc (the Command-Line Compiler from Microsoft's SDK for Java /
|
|
|
|
Visual J++)</li>
|
2001-08-01 15:54:24 +00:00
|
|
|
<li>kjc (the <a href="http://www.dms.at/kopi/" target="_top">kopi</a>
|
|
|
|
compiler)</li>
|
|
|
|
<li>gcj (the gcj compiler from gcc)</li>
|
2001-02-13 12:32:01 +00:00
|
|
|
</ul>
|
|
|
|
<p>For JDK 1.1/1.2, classic is the default. For JDK 1.3, modern is the default.
|
|
|
|
If you wish to use a different compiler interface than one of the four
|
|
|
|
supplied, write a class that implements the CompilerAdapter interface
|
|
|
|
(package org.apache.tools.ant.taskdefs.compilers). Supply the full
|
|
|
|
classname in the "build.compiler" property.
|
|
|
|
</p>
|
2001-06-13 15:29:47 +00:00
|
|
|
<p>This task will drop all entries that point to non-existant
|
|
|
|
files/directories from the CLASSPATH it passes to the compiler.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">srcdir</td>
|
2001-02-14 10:58:24 +00:00
|
|
|
<td valign="top">location of the java files. (See Notes at the end)</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
<td align="center" valign="top">Yes, unless nested <code><src></code> elements are present.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">destdir</td>
|
|
|
|
<td valign="top">location to store the class files.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">includes</td>
|
|
|
|
<td valign="top">comma-separated list of patterns of files that must be
|
|
|
|
included; all files are included when omitted.</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">includesfile</td>
|
|
|
|
<td valign="top">the name of a file that contains
|
|
|
|
include patterns.</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">excludes</td>
|
|
|
|
<td valign="top">comma-separated list of patterns of files that must be
|
|
|
|
excluded; no files (except default excludes) are excluded when omitted.</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">excludesfile</td>
|
|
|
|
<td valign="top">the name of a file that contains
|
|
|
|
exclude patterns.</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">defaultexcludes</td>
|
|
|
|
<td valign="top">indicates whether default excludes should be used
|
|
|
|
(<code>yes</code> | <code>no</code>); default excludes are used when omitted.</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">classpath</td>
|
|
|
|
<td valign="top">the classpath to use.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">bootclasspath</td>
|
|
|
|
<td valign="top">location of bootstrap class files.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">classpathref</td>
|
|
|
|
<td valign="top">the classpath to use, given as a
|
|
|
|
<a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">bootclasspathref</td>
|
|
|
|
<td valign="top">location of bootstrap class files, given as a
|
|
|
|
<a href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">extdirs</td>
|
|
|
|
<td valign="top">location of installed extensions.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">encoding</td>
|
2001-08-01 15:54:24 +00:00
|
|
|
<td valign="top">encoding of source files. (gcj doesn't support
|
|
|
|
this option yet)</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">debug</td>
|
|
|
|
<td valign="top">indicates whether source should be compiled with debug
|
|
|
|
information; defaults to <code>off</code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">optimize</td>
|
|
|
|
<td valign="top">indicates whether source should be compiled with
|
|
|
|
optimization; defaults to <code>off</code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">deprecation</td>
|
|
|
|
<td valign="top">indicates whether source should be compiled with
|
|
|
|
deprecation information; defaults to <code>off</code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">target</td>
|
|
|
|
<td valign="top">generate class files for specific VM version (e.g.,
|
|
|
|
<code>1.1</code> or <code>1.2</code>).</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">verbose</td>
|
|
|
|
<td valign="top">asks the compiler for verbose output.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">depend</td> <td valign="top">enables dependency-tracking
|
|
|
|
for compilers that support this (jikes and classic)</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">includeAntRuntime</td>
|
|
|
|
<td valign="top">whether to include the Ant run-time libraries;
|
2001-02-18 13:44:44 +00:00
|
|
|
defaults to <code>yes</code>.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">includeJavaRuntime</td>
|
|
|
|
<td valign="top">whether to include the default run-time
|
|
|
|
libraries from the executing VM; defaults to <code>no</code>.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">failonerror</td> <td valign="top">
|
|
|
|
indicates whether the build will continue even if there are compilation errors; defaults to <code>true</code>.
|
|
|
|
</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<h3>Parameters specified as nested elements</h3>
|
|
|
|
<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
|
|
|
|
supports all attributes of <code><fileset></code>
|
|
|
|
(<code>dir</code> becomes <code>srcdir</code>) as well as the nested
|
|
|
|
<code><include></code>, <code><exclude></code> and
|
|
|
|
<code><patternset></code> elements.</p>
|
|
|
|
<h4><code>src</code>, <code>classpath</code>, <code>bootclasspath</code> and <code>extdirs</code></h4>
|
|
|
|
<p><code>Javac</code>'s <i>srcdir</i>, <i>classpath</i>,
|
|
|
|
<i>bootclasspath</i> and <i>extdirs</i> attributes are <a
|
|
|
|
href="../using.html#path">path-like structures</a> and can also be set via nested
|
|
|
|
<code><src></code>,
|
|
|
|
<code><classpath></code>,
|
|
|
|
<code><bootclasspath></code> and
|
|
|
|
<code><extdirs></code> elements, respectively.</p>
|
|
|
|
|
|
|
|
<h3>Examples</h3>
|
|
|
|
<pre> <javac srcdir="${src}"
|
|
|
|
destdir="${build}"
|
|
|
|
classpath="xyz.jar"
|
|
|
|
debug="on"
|
|
|
|
/></pre>
|
|
|
|
<p>compiles all <code>.java</code> files under the <code>${src}</code>
|
|
|
|
directory, and stores
|
|
|
|
the <code>.class</code> files in the <code>${build}</code> directory.
|
|
|
|
The classpath used contains <code>xyz.jar</code>, and debug information is on.</p>
|
|
|
|
<pre> <javac srcdir="${src}"
|
|
|
|
destdir="${build}"
|
|
|
|
includes="mypackage/p1/**,mypackage/p2/**"
|
|
|
|
excludes="mypackage/p1/testpackage/**"
|
|
|
|
classpath="xyz.jar"
|
|
|
|
debug="on"
|
|
|
|
/></pre>
|
|
|
|
<p>compiles <code>.java</code> files under the <code>${src}</code>
|
|
|
|
directory, and stores the
|
|
|
|
<code>.class</code> files in the <code>${build}</code> directory.
|
|
|
|
The classpath used contains <code>xyz.jar</code>, and debug information is on.
|
|
|
|
Only files under <code>mypackage/p1</code> and <code>mypackage/p2</code> are
|
|
|
|
used. Files in the <code>mypackage/p1/testpackage</code> directory are excluded
|
|
|
|
from compilation.</p>
|
|
|
|
|
|
|
|
<pre> <javac srcdir="${src}:${src2}"
|
|
|
|
destdir="${build}"
|
|
|
|
includes="mypackage/p1/**,mypackage/p2/**"
|
|
|
|
excludes="mypackage/p1/testpackage/**"
|
|
|
|
classpath="xyz.jar"
|
|
|
|
debug="on"
|
|
|
|
/></pre>
|
|
|
|
|
|
|
|
<p>is the same as the previous example, with the addition of a second
|
|
|
|
source path, defined by
|
|
|
|
the property <code>src2</code>. This can also be represented using nested
|
|
|
|
<code><src></code> elements as follows:</p>
|
|
|
|
|
|
|
|
<pre> <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></pre>
|
|
|
|
|
|
|
|
<p><b>Note:</b> 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.</p>
|
|
|
|
|
2001-02-14 10:58:24 +00:00
|
|
|
<p><b>Note:</b> If you wish to compile only source-files located in some packages below a
|
|
|
|
common root you should not include these packages in the srcdir-attribute. Use include/exclude-attributes
|
|
|
|
or elements to filter for these packages. If you include part of your package-structure inside the srcdir-attribute
|
|
|
|
(or nested src-elements) Ant will start to recompile your sources everytime you call it.</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<hr>
|
|
|
|
<p align="center">Copyright © 2000,2001 Apache Software Foundation. All rights
|
|
|
|
Reserved.</p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|