diff --git a/docs/manual/CoreTasks/javac.html b/docs/manual/CoreTasks/javac.html index 23dd77587..5dae4f78b 100644 --- a/docs/manual/CoreTasks/javac.html +++ b/docs/manual/CoreTasks/javac.html @@ -11,56 +11,84 @@

Description

Compiles a Java source tree.

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.

+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.

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 +the classes that need a rebuild. It will not scan the source and therefore will have no knowledge about nested classes, classes that are named different -from the source file and so on.

-

The directory structure of the source tree should follow the package +from the source file, and so on. See the +<depend> task +for dependency checking based on other than just +existence/modification times. +

When the source files are part of a package, the directory structure of +the source tree should follow the package hierarchy.

-

It is possible to refine the set of files that are being compiled/copied. -This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes -attributes. With the includes or includesfile attribute you specify the files you want to -have included by using patterns. The exclude or excludesfile attribute is used to specify -the files you want to have excluded. This is also done with patterns. And -finally with the defaultexcludes attribute, you can specify whether you -want to use default exclusions or not. See the section on directory based tasks, on how the -inclusion/exclusion of files works, and how to write patterns.

-

It is possible to use different compilers. This can be selected with the -"build.compiler" property or the compiler attribute. Here are the choices:-

+

It is possible to refine the set of files that are being compiled. +This can be done with the includes, includesfile, +excludes, excludesfile, +and defaultexcludes +attributes. With the includes or +includesfile attribute, you specify the files you want to +have included. +The exclude or excludesfile attribute is used +to specify +the files you want to have excluded. In both cases, the list of files +can be specified by either the filename, relative to the directory(s) specified +in the srcdir attribute or nested element, or by using +wildcard patterns. See the section on +directory-based tasks, +for information on how the +inclusion/exclusion of files works, and how to write wildcard patterns.

+

It is possible to use different compilers. This can be specified by +either setting the global build.compiler property, which will +affect all <javac> tasks throughout the build, or by +setting the compiler attribute, specific to the current +<javac> task. +Valid values for either the +build.compiler property or the compiler +attribute are:

-

For JDK 1.1/1.2, classic is the default. For JDK 1.3/1.4, modern is the default. + +

For JDK 1.1/1.2, classic is the default. +For JDK 1.3/1.4, modern is the default. If you wish to use a different compiler interface than those -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. +supplied, you can write a class that implements the CompilerAdapter interface +(package org.apache.tools.ant.taskdefs.compilers). Supply the full +classname in the build.compiler property or the +compiler attribute.

-

The fork attribute overrides the build.compiler setting and expects -a JDK1.1 or higher to be set in java.home. +

The fork attribute overrides the build.compiler property +or compiler attribute setting and +expects a JDK1.1 or higher to be set in JAVA_HOME.

This task will drop all entries that point to non-existent -files/directories from the CLASSPATH it passes to the compiler.

+files/directories from the classpath it passes to the compiler.

Windows Note:When the modern compiler is used in unforked mode on Windows, it locks up the files present in the -classpath of the <javac> task, and does not release them. The side -effect of this is that you will not be able to delete or move +classpath of the <javac> task, and does not release them. +The side effect of this is that you will not be able to delete or move those files later on in the build. The workaround is to fork when invoking the compiler.

@@ -73,196 +101,211 @@ invoking the compiler.

srcdir - location of the java files. (See Notes at the end) + Location of the java files. (See the + Note below.) Yes, unless nested <src> elements are present. destdir - location to store the class files. + Location to store the class files. No includes - comma-separated list of patterns of files that must be - included; all files are included when omitted. + Comma-separated list of files (may be specified using + wildcard patterns) that must be + included; all .java files are included when omitted. No includesfile - the name of a file that contains - include patterns. + The name of a file that contains a list of files to + include (may be specified using wildcard patterns). No excludes - comma-separated list of patterns of files that must be - excluded; no files (except default excludes) are excluded when omitted. + Comma-separated list of files (may be specified using + wildcard patterns) that must be excluded; no files (except default + excludes) are excluded when omitted. No excludesfile - the name of a file that contains - exclude patterns. - No - - - defaultexcludes - indicates whether default excludes should be used - (yes | no); default excludes are used when omitted. + The name of a file that contains a list of files to + exclude (may be specified using wildcard patterns). No classpath - the classpath to use. + The classpath to use. No sourcepath - the sourcepath to use; defaults to the value of the srcdir attribute (or <src> elements). + The sourcepath to use; defaults to the value of the srcdir attribute (or nested <src> elements). To suppress the sourcepath switch, use sourcepath="". No bootclasspath - location of bootstrap class files. + Location of bootstrap class files. No classpathref - the classpath to use, given as a - reference to a PATH defined elsewhere. + The classpath to use, given as a + reference to a path defined elsewhere. No sourcepathref - the sourcepath to use, given as a - reference to a PATH defined elsewhere. + The sourcepath to use, given as a + reference to a path defined elsewhere. No bootclasspathref - location of bootstrap class files, given as a - reference to a PATH defined elsewhere. + Location of bootstrap class files, given as a + reference to a path defined elsewhere. No extdirs - location of installed extensions. + Location of installed extensions. No encoding - encoding of source files. (gcj doesn't support - this option yet) + Encoding of source files. (Note: gcj doesn't support + this option yet.) No nowarn - indicates whether -nowarn switch should be passed - to the compiler; defaults to off. + Indicates whether the -nowarn switch + should be passed to the compiler; defaults to off. No debug - indicates whether source should be compiled with debug + Indicates whether source should be compiled with debug information; defaults to off. No + + debuglevel + Keyword list to be appended to the -g + command-line switch. This will be ignored by all implementations except + modern and classic(ver >= 1.2). + Legal values are none or a comma-separated list of the + following keywords: + lines, vars, and source. + If debuglevel is not specified, by default, + :none will be + appended to -g. If debug is not turned on, + this attribute will be ignored. + + No + optimize - indicates whether source should be compiled with + Indicates whether source should be compiled with optimization; defaults to off. No deprecation - indicates whether source should be compiled with + Indicates whether source should be compiled with deprecation information; defaults to off. No target - generate class files for specific VM version (e.g., + Generate class files for specific VM version (e.g., 1.1 or 1.2). No verbose - asks the compiler for verbose output. + Asks the compiler for verbose output. No - depend enables dependency-tracking - for compilers that support this (jikes and classic) + depend Enables dependency-tracking + for compilers that support this (jikes and + classic). No includeAntRuntime - whether to include the Ant run-time libraries; - defaults to yes. + Whether to include the Ant run-time libraries in the + classpath; defaults to yes. No includeJavaRuntime - whether to include the default run-time - libraries from the executing VM; defaults to no. + Whether to include the default run-time + libraries from the executing VM in the classpath; + defaults to yes. No fork - whether to execute Javac using the JDK compiler - externally; defaults to no. You can also give a - complete path to the javac executable to use instead of - yes, which would run the compiler of the Java - vesrion that is currently running Ant. + Whether to execute javac using the + JDK compiler externally; defaults to no. You can also + give a complete path to the javac executable to use + instead of yes, which would run the compiler of the Java + version that is currently running Ant. No memoryInitialSize - the initial size of the memory for the underlying VM, if javac is run - externally, ignored otherwise; defaults to the standard VM memory setting. - (examples: 83886080, 81920k, or 80m) + The initial size of the memory for the underlying VM, + if javac is run externally; ignored otherwise. Defaults + to the standard VM memory setting. + (Examples: 83886080, 81920k, or + 80m) No memoryMaximumSize - the maximum size of the memory for the underlying VM, if javac is run - externally, ignored otherwise; defaults to the standard VM memory setting. - (examples: 83886080, 81920k, or 80m) + The maximum size of the memory for the underlying VM, + if javac is run externally; ignored otherwise. Defaults + to the standard VM memory setting. + (Examples: 83886080, 81920k, or + 80m) No failonerror - indicates whether the build will continue even if there are compilation errors; defaults to true. + Indicates whether the build will continue even if there are compilation errors; defaults to true. No source - Value of the -source command line - switch, will be ignored by all implementations except - modern, legal values are "1.3" and - "1.4" - by default, no -source argument + Value of the -source command-line + switch; will be ignored by all implementations except + modern. Legal values are 1.3 and + 1.4 – by default, no -source argument will be used at all. No - debuglevel - Keyword list to be appended to the -g command line - switch. This will be ignored by all implementations except - modern and classic(ver >= 1.2), legal values are - "none" or a comma separated list of the following keywords. - Valid keywords are "lines", "vars" and "source" - - if debuglevel is not specified, by default, nothing will be - appended to -g. If debug is not turned on, this attribute will be - ignored. - + compiler + The compiler implementation to use. + If this attribute is not set, the value of the + build.compiler property, if set, will be used. + Otherwise, the default compiler for the current VM will be used. + (See the above list of valid + compilers.) No - compiler - The compiler implementation to use. - Defaults to the value of the build.compiler property. + listfiles + Indicates whether the source files to be compiled will + be listed; defaults to no. No @@ -275,9 +318,11 @@ supports all attributes of <fileset> <patternset> elements.

src, classpath, sourcepath, bootclasspath and extdirs

-

Javac's srcdir, classpath, -sourcepath, bootclasspath and extdirs attributes are path-like structures and can also be set via nested +

<javac>'s srcdir, classpath, +sourcepath, bootclasspath, and +extdirs attributes are +path-like structures +and can also be set via nested <src>, <classpath>, <sourcepath>, @@ -300,7 +345,8 @@ used.

value - See here + See + Command-line Arguments. Exactly one of these. @@ -314,10 +360,12 @@ used.

implementation - Only use this argument if the chosen - implementation matches this attribute. Possible choices are the - same as those of the build.compiler property. - No. + Only pass the specified argument if the chosen + implementation matches the value of this attribute. + Legal values are the + same as those in the above list of valid + compilers.) + No @@ -330,7 +378,8 @@ used.

compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. -The classpath used contains xyz.jar, and debug information is on.

+The classpath used includes xyz.jar, and compiling with +debug information is on.

  <javac srcdir="${src}"
          destdir="${build}"
@@ -339,7 +388,7 @@ The classpath used contains xyz.jar, and debug information is on.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.

+compiler using the default javac executable.

  <javac srcdir="${src}"
          destdir="${build}"
@@ -348,7 +397,7 @@ compiler using the default javac executable.

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 +compiler, using the executable named java$javac.exe. Note that the $ sign needs to be escaped by a second one.

  <javac srcdir="${src}"
@@ -361,10 +410,10 @@ that the $ sign needs to be escaped by a second one.

compiles .java files under the ${src} directory, and stores the .class files in the ${build} directory. -The classpath used contains xyz.jar, and debug information is on. +The classpath used includes xyz.jar, and debug information is on. Only files under mypackage/p1 and mypackage/p2 are -used. Files in the mypackage/p1/testpackage directory are excluded -from compilation.

+used. All files in and below the mypackage/p1/testpackage +directory are excluded from compilation.

  <javac srcdir="${src}:${src2}"
          destdir="${build}"
@@ -389,64 +438,95 @@ the property src2. This can also be represented using nested
     <exclude name="mypackage/p1/testpackage/**"/>
   </javac>
-

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.

+

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 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 every time you call it.

+

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.

Jikes Notes

Jikes supports some extra options, which can be set be defining -properties prior to invoking the task. The ant developers are aware that -this is ugly and inflexible -expect a better solution in the future. All -the options are boolean, and must be set to "true" or "yes" to be -interpreted as anything other than false; by default -build.compiler.warnings is "true" while all others are "false"

+the properties shown below prior to invoking the task. The setting +for each property will be in affect for all <javac> +tasks throughout the build. +The Ant developers are aware that +this is ugly and inflexible – expect a better solution in the future. +All the options are boolean, and must be set to true or +yes to be +interpreted as anything other than false. By default, +build.compiler.warnings is true, +while all others are false.

+ + + + + + + + +
PropertyDescriptionDefault
build.compiler.emacs - Enable emacs compatible error messages + Enable emacs-compatible error messages. + false +
- build.compiler.warnings
- This property has been deprecated, use the nowarn attribute - instead + build.compiler.fulldepend
- don't disable warning messages + Enable full dependency checking; see
+ the +F switch in the Jikes manual.
+ false +
build.compiler.pedantic - enable pedantic warnings + Enable pedantic warnings. + false +
- build.compiler.fulldepend + build.compiler.warnings
+ Deprecated. Use + <javac>'s nowarn + attribute instead.
- enable full dependency checking,
- "+F" in the jikes manual. + Don't disable warning messages.
+ true +
+

+
-

Copyright © 2001-2002 Apache Software Foundation. All rights -Reserved.

+

Copyright © 2001-2002 Apache Software Foundation. +All rights Reserved.