Google

Javac (Apache Ant API)

org.apache.tools.ant.taskdefs
Class Javac


java.lang.Object

  |

  +--org.apache.tools.ant.ProjectComponent

        |

        +--org.apache.tools.ant.Task

              |

              +--org.apache.tools.ant.taskdefs.MatchingTask

                    |

                    +--org.apache.tools.ant.taskdefs.Javac

All Implemented Interfaces:
SelectorContainer

public class Javac
extends MatchingTask

Compiles Java source files. This task can take the following arguments:

  • sourcedir
  • destdir
  • deprecation
  • classpath
  • bootclasspath
  • extdirs
  • optimize
  • debug
  • encoding
  • target
  • depend
  • vebose
  • failonerror
  • includeantruntime
  • includejavaruntime
  • source
  • compiler
Of these arguments, the sourcedir and destdir are required.

When this task executes, it will recursively scan the sourcedir and destdir looking for Java source files to compile. This task makes its compile decision based on timestamp.

Since:
Ant 1.1
Version:
$Revision: 1.102.2.2 $
Author:
James Davidson duncan@x180.com
, Robin Green greenrd@hotmail.com , Stefan Bodewig , J D Glanville

Nested Class Summary
 class Javac.ImplementationSpecificArgument
          Adds an "compiler" attribute to Commandline$Attribute used to filter command line attributes based on the current implementation.
 
Field Summary
protected  java.io.File[] compileList
           
protected  boolean failOnError
           
protected  boolean listFiles
           
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset, useDefaultExcludes
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
Javac()
          Javac task for compilation of Java files.
 
Method Summary
protected  void checkParameters()
          Check that all required attributes have been set and nothing silly has been entered.
protected  void compile()
          Perform the compilation.
 Path createBootclasspath()
          Adds a path to the bootclasspath.
 Path createClasspath()
          Adds a path to the classpath.
 Javac.ImplementationSpecificArgument createCompilerArg()
          Adds an implementation specific command-line argument.
 Path createExtdirs()
          Adds a path to extdirs.
 Path createSourcepath()
          Adds a path to sourcepath.
 Path createSrc()
          Adds a path for source compilation.
 void execute()
          Executes the task.
 Path getBootclasspath()
          Gets the bootclasspath that will be used to compile the classes against.
 Path getClasspath()
          Gets the classpath to be used for this compilation.
 java.lang.String getCompiler()
          The implementation for this particular task.
 java.lang.String getCompilerVersion()
          The implementation for this particular task.
 java.lang.String[] getCurrentCompilerArgs()
          Get the additional implementation specific command line arguments.
 boolean getDebug()
          Gets the debug flag.
 java.lang.String getDebugLevel()
          Get the value of debugLevel.
 boolean getDepend()
          Gets the depend flag.
 boolean getDeprecation()
          Gets the deprecation flag.
 java.io.File getDestdir()
          Gets the destination directory into which the java source files should be compiled.
 java.lang.String getEncoding()
          Gets the java source file encoding name.
 Path getExtdirs()
          Gets the extension directories that will be used during the compilation.
 boolean getFailonerror()
          Gets the failonerror flag.
 java.io.File[] getFileList()
          Gets the list of files to be compiled.
 boolean getIncludeantruntime()
          Gets whether or not the ant classpath is to be included in the classpath.
 boolean getIncludejavaruntime()
          Gets whether or not the java runtime should be included in this task's classpath.
 java.lang.String getJavacExecutable()
          The name of the javac executable to use in fork-mode.
 boolean getListfiles()
          Get the listfiles flag.
 java.lang.String getMemoryInitialSize()
          Gets the memoryInitialSize flag.
 java.lang.String getMemoryMaximumSize()
          Gets the memoryMaximumSize flag.
 boolean getNowarn()
          Should the -nowarn option be used.
 boolean getOptimize()
          Gets the optimize flag.
 java.lang.String getSource()
          Get the value of source.
 Path getSourcepath()
          Gets the sourcepath to be used for this compilation.
 Path getSrcdir()
          Gets the source dirs to find the source java files.
protected  java.lang.String getSystemJavac()
           
 java.lang.String getTarget()
          Gets the target VM that the classes will be compiled for.
 boolean getVerbose()
          Gets the verbose flag.
 boolean isForkedJavac()
          Is this a forked invocation of JDK's javac?
protected  boolean isJdkCompiler(java.lang.String compilerImpl)
           
protected  Path recreateSrc()
          Recreate src.
protected  void resetFileLists()
          Clear the list of files to be compiled and copied..
protected  void scanDir(java.io.File srcDir, java.io.File destDir, java.lang.String[] files)
          Scans the directory looking for source files to be compiled.
 void setBootclasspath(Path bootclasspath)
          Sets the bootclasspath that will be used to compile the classes against.
 void setBootClasspathRef(Reference r)
          Adds a reference to a classpath defined elsewhere.
 void setClasspath(Path classpath)
          Set the classpath to be used for this compilation.
 void setClasspathRef(Reference r)
          Adds a reference to a classpath defined elsewhere.
 void setCompiler(java.lang.String compiler)
          Choose the implementation for this particular task.
 void setDebug(boolean debug)
          Indicates whether source should be compiled with debug information; defaults to off.
 void setDebugLevel(java.lang.String v)
          Keyword list to be appended to the -g command-line switch.
 void setDepend(boolean depend)
          Enables dependency-tracking for compilers that support this (jikes and classic).
 void setDeprecation(boolean deprecation)
          Indicates whether source should be compiled with deprecation information; defaults to off.
 void setDestdir(java.io.File destDir)
          Set the destination directory into which the Java source files should be compiled.
 void setEncoding(java.lang.String encoding)
          Set the Java source file encoding name.
 void setExecutable(java.lang.String forkExec)
          Sets the the name of the javac executable.
 void setExtdirs(Path extdirs)
          Sets the extension directories that will be used during the compilation.
 void setFailonerror(boolean fail)
          Indicates whether the build will continue even if there are compilation errors; defaults to true.
 void setFork(boolean f)
          If true, forks the javac compiler.
 void setIncludeantruntime(boolean include)
          If true, includes Ant's own classpath in the classpath.
 void setIncludejavaruntime(boolean include)
          If true, includes the Java runtime libraries in the classpath.
 void setListfiles(boolean list)
          If true, list the source files being handed off to the compiler.
 void setMemoryInitialSize(java.lang.String memoryInitialSize)
          The initial size of the memory for the underlying VM if javac is run externally; ignored otherwise.
 void setMemoryMaximumSize(java.lang.String memoryMaximumSize)
          The maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise.
 void setNowarn(boolean flag)
          If true, enables the -nowarn option.
 void setOptimize(boolean optimize)
          If true, compiles with optimization enabled.
 void setProceed(boolean proceed)
           
 void setSource(java.lang.String v)
          Value of the -source command-line switch; will be ignored by all implementations except modern and jikes.
 void setSourcepath(Path sourcepath)
          Set the sourcepath to be used for this compilation.
 void setSourcepathRef(Reference r)
          Adds a reference to a source path defined elsewhere.
 void setSrcdir(Path srcDir)
          Set the source directories to find the source Java files.
 void setTarget(java.lang.String target)
          Sets the target VM that the classes will be compiled for.
 void setVerbose(boolean verbose)
          If true, asks the compiler for verbose output.
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
addAnd, addContains, addCustom, addDate, addDepend, addDepth, addFilename, addMajority, addNone, addNot, addOr, addPresent, addSelector, addSize, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

failOnError


protected boolean failOnError

listFiles


protected boolean listFiles

compileList


protected java.io.File[] compileList
Constructor Detail

Javac


public Javac()
Javac task for compilation of Java files.

Method Detail

getDebugLevel


public java.lang.String getDebugLevel()
Get the value of debugLevel.

Returns:
value of debugLevel.

setDebugLevel


public void setDebugLevel(java.lang.String v)
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.

Parameters:
v - Value to assign to debugLevel.

getSource


public java.lang.String getSource()
Get the value of source.

Returns:
value of source.

setSource


public void setSource(java.lang.String v)
Value of the -source command-line switch; will be ignored by all implementations except modern and jikes. If you use this attribute together with jikes, you must make sure that your version of jikes supports the -source switch. Legal values are 1.3 and 1.4 - by default, no -source argument will be used at all.

Parameters:
v - Value to assign to source.

createSrc


public Path createSrc()
Adds a path for source compilation.

Returns:
a nested src element.

recreateSrc


protected Path recreateSrc()
Recreate src.

Returns:
a nested src element.

setSrcdir


public void setSrcdir(Path srcDir)
Set the source directories to find the source Java files.


getSrcdir


public Path getSrcdir()
Gets the source dirs to find the source java files.


setDestdir


public void setDestdir(java.io.File destDir)
Set the destination directory into which the Java source files should be compiled.


getDestdir


public java.io.File getDestdir()
Gets the destination directory into which the java source files should be compiled.


setSourcepath


public void setSourcepath(Path sourcepath)
Set the sourcepath to be used for this compilation.


getSourcepath


public Path getSourcepath()
Gets the sourcepath to be used for this compilation.


createSourcepath


public Path createSourcepath()
Adds a path to sourcepath.


setSourcepathRef


public void setSourcepathRef(Reference r)
Adds a reference to a source path defined elsewhere.


setClasspath


public void setClasspath(Path classpath)
Set the classpath to be used for this compilation.

Parameters:
classpath - an Ant Path object containing the compilation classpath.

getClasspath


public Path getClasspath()
Gets the classpath to be used for this compilation.


createClasspath


public Path createClasspath()
Adds a path to the classpath.


setClasspathRef


public void setClasspathRef(Reference r)
Adds a reference to a classpath defined elsewhere.


setBootclasspath


public void setBootclasspath(Path bootclasspath)
Sets the bootclasspath that will be used to compile the classes against.


getBootclasspath


public Path getBootclasspath()
Gets the bootclasspath that will be used to compile the classes against.


createBootclasspath


public Path createBootclasspath()
Adds a path to the bootclasspath.


setBootClasspathRef


public void setBootClasspathRef(Reference r)
Adds a reference to a classpath defined elsewhere.


setExtdirs


public void setExtdirs(Path extdirs)
Sets the extension directories that will be used during the compilation.


getExtdirs


public Path getExtdirs()
Gets the extension directories that will be used during the compilation.


createExtdirs


public Path createExtdirs()
Adds a path to extdirs.


setListfiles


public void setListfiles(boolean list)
If true, list the source files being handed off to the compiler.


getListfiles


public boolean getListfiles()
Get the listfiles flag.


setFailonerror


public void setFailonerror(boolean fail)
Indicates whether the build will continue even if there are compilation errors; defaults to true.


setProceed


public void setProceed(boolean proceed)

getFailonerror


public boolean getFailonerror()
Gets the failonerror flag.


setDeprecation


public void setDeprecation(boolean deprecation)
Indicates whether source should be compiled with deprecation information; defaults to off.


getDeprecation


public boolean getDeprecation()
Gets the deprecation flag.


setMemoryInitialSize


public void setMemoryInitialSize(java.lang.String 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)


getMemoryInitialSize


public java.lang.String getMemoryInitialSize()
Gets the memoryInitialSize flag.


setMemoryMaximumSize


public void setMemoryMaximumSize(java.lang.String 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)


getMemoryMaximumSize


public java.lang.String getMemoryMaximumSize()
Gets the memoryMaximumSize flag.


setEncoding


public void setEncoding(java.lang.String encoding)
Set the Java source file encoding name.


getEncoding


public java.lang.String getEncoding()
Gets the java source file encoding name.


setDebug


public void setDebug(boolean debug)
Indicates whether source should be compiled with debug information; defaults to off.


getDebug


public boolean getDebug()
Gets the debug flag.


setOptimize


public void setOptimize(boolean optimize)
If true, compiles with optimization enabled.


getOptimize


public boolean getOptimize()
Gets the optimize flag.


setDepend


public void setDepend(boolean depend)
Enables dependency-tracking for compilers that support this (jikes and classic).


getDepend


public boolean getDepend()
Gets the depend flag.


setVerbose


public void setVerbose(boolean verbose)
If true, asks the compiler for verbose output.


getVerbose


public boolean getVerbose()
Gets the verbose flag.


setTarget


public void setTarget(java.lang.String target)
Sets the target VM that the classes will be compiled for. Valid strings are "1.1", "1.2", and "1.3".


getTarget


public java.lang.String getTarget()
Gets the target VM that the classes will be compiled for.


setIncludeantruntime


public void setIncludeantruntime(boolean include)
If true, includes Ant's own classpath in the classpath.


getIncludeantruntime


public boolean getIncludeantruntime()
Gets whether or not the ant classpath is to be included in the classpath.


setIncludejavaruntime


public void setIncludejavaruntime(boolean include)
If true, includes the Java runtime libraries in the classpath.


getIncludejavaruntime


public boolean getIncludejavaruntime()
Gets whether or not the java runtime should be included in this task's classpath.


setFork


public void setFork(boolean f)
If true, forks the javac compiler.

Parameters:
f - "true|false|on|off|yes|no"

setExecutable


public void setExecutable(java.lang.String forkExec)
Sets the the name of the javac executable.

Ignored unless fork is true or extJavac has been specified as the compiler.


isForkedJavac


public boolean isForkedJavac()
Is this a forked invocation of JDK's javac?


getJavacExecutable


public java.lang.String getJavacExecutable()
The name of the javac executable to use in fork-mode.


setNowarn


public void setNowarn(boolean flag)
If true, enables the -nowarn option.


getNowarn


public boolean getNowarn()
Should the -nowarn option be used.


createCompilerArg


public Javac.ImplementationSpecificArgument createCompilerArg()
Adds an implementation specific command-line argument.


getCurrentCompilerArgs


public java.lang.String[] getCurrentCompilerArgs()
Get the additional implementation specific command line arguments.

Returns:
array of command line arguments, guaranteed to be non-null.

execute


public void execute()
             throws BuildException
Executes the task.

Overrides:
execute in class Task
Throws:
BuildException - if something goes wrong with the build

resetFileLists


protected void resetFileLists()
Clear the list of files to be compiled and copied..


scanDir


protected void scanDir(java.io.File srcDir,
                       java.io.File destDir,
                       java.lang.String[] files)
Scans the directory looking for source files to be compiled. The results are returned in the class variable compileList


getFileList


public java.io.File[] getFileList()
Gets the list of files to be compiled.


isJdkCompiler


protected boolean isJdkCompiler(java.lang.String compilerImpl)

getSystemJavac


protected java.lang.String getSystemJavac()

setCompiler


public void setCompiler(java.lang.String compiler)
Choose the implementation for this particular task.

Since:
Ant 1.5

getCompiler


public java.lang.String getCompiler()
The implementation for this particular task.

Defaults to the build.compiler property but can be overriden via the compiler and fork attributes.

If fork has been set to true, the result will be extJavac and not classic or java1.2 - no matter what the compiler attribute looks like.

Since:
Ant 1.5
See Also:
getCompilerVersion()

getCompilerVersion


public java.lang.String getCompilerVersion()
The implementation for this particular task.

Defaults to the build.compiler property but can be overriden via the compiler attribute.

This method does not take the fork attribute into account.

Since:
Ant 1.5
See Also:
getCompiler()

checkParameters


protected void checkParameters()
                        throws BuildException
Check that all required attributes have been set and nothing silly has been entered.

BuildException
Since:
Ant 1.5

compile


protected void compile()
Perform the compilation.

Since:
Ant 1.5


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.