Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Javac

extends MatchingTask
Class Inheritance
Imports
java.io.File, .IOException, .OutputStream, java.nio.charset.StandardCharsets, java.nio.file.Files, java.util.ArrayList, .Collection, .HashMap, .List, .Map, .TreeMap, org.apache.tools.ant.BuildException, .DirectoryScanner, .MagicNames, .Project, org.apache.tools.ant.taskdefs.compilers.CompilerAdapter, .CompilerAdapterExtension, .CompilerAdapterFactory, org.apache.tools.ant.types.Path, .Reference, org.apache.tools.ant.util.FileUtils, .GlobPatternMapper, .JavaEnvUtils, .SourceFileScanner, org.apache.tools.ant.util.facade.FacadeTaskHelper

Compiles Java source files. This task can take the following arguments: 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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
Javac.ImplementationSpecificArgument

Adds an "compiler" attribute to Commandline$Attribute used to filter command line attributes based on the current implementation.

Field Summary

Modifier and TypeField and Description
private Path
private Path
protected File[]
private Path
private boolean
private boolean
private String
private boolean
private boolean
private File
private String
private String
private Path
private FacadeTaskHelper
private static final String
protected boolean
private static final FileUtils
private boolean
private String
private static final char
private static final char
private static final char
private Boolean
private boolean
private boolean
protected boolean
private String
private String
private static final String
private Path
private Path
private File
private CompilerAdapter
private boolean
private boolean
private static final byte[]
private static final byte[]
private Map<String, Long>
private String
private String
private Path
private String
private boolean
private File
private String
private Path
private boolean
Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
fileset

Constructor Summary

AccessConstructor and Description
public
Javac()

Javac task for compilation of Java files.

Method Summary

Modifier and TypeMethod and Description
public void
add(final CompilerAdapter
CompilerAdapter
adapter
)

Set the compiler adapter explicitly.

private String
protected void
checkParameters()

Check that all required attributes have been set and nothing silly has been entered.

private void
private void
protected void
compile()

Perform the compilation.

public Path

Returns:

a path to be configured
createBootclasspath
()

Adds a path to the bootclasspath.

public Path

Returns:

a class path to be configured
createClasspath
()

Adds a path to the classpath.

public Javac.ImplementationSpecificArgument

Returns:

a ImplementationSpecificArgument to be configured
createCompilerArg
()

Adds an implementation specific command-line argument.

public Path

Returns:

Path
createCompilerClasspath
()

The classpath to use when loading the compiler implementation if it is not a built-in one.

public Path

Returns:

a path to be configured
createExtdirs
()

Adds a path to extdirs.

public Path

Returns:

a modulepath to be configured
createModulepath
()

Adds a path to the modulepath.

public Path

Returns:

a modulesourcepath to be configured
createModulesourcepath
()

Adds a path to modulesourcepath.

public Path

Returns:

a sourcepath to be configured
createSourcepath
()

Adds a path to sourcepath.

public Path

Returns:

a nested src element.
createSrc
()

Adds a path for source compilation.

public Path

Returns:

an upgrademodulepath to be configured
createUpgrademodulepath
()

Adds a path to the upgrademodulepath.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Executes the task.
private static Collection<? extends CharSequence>

Returns:

the possible alternatives
expandGroups
(final CharSequence
the entry to expand groups in
element
)

Expands the groups in the modulesourcepath entry to alternatives.

private static void
findModules(final File
the project root
root
,
String
the expanded modulesourcepath entry
pattern
,
final Map<String, Collection<File>>
the map to put modules into
collector
)

Finds modules in the expanded modulesourcepath entry.

private static void
findModules(final File
the project root
root
,
final String
the path to modules folder
pathToModule
,
final String
the path in module to source folder
pathInModule
,
final Map<String, Collection<File>>
the map to put modules into
collector
)

Finds modules in the expanded modulesourcepath entry.

private String[]
private void
generateMissingPackageInfoClasses(final File dest)

Ensure that every package-info.java produced a package-info.class.

private String
getAltCompilerName(final String anImplementation)

public Path

Returns:

the boot path
getBootclasspath
()

Gets the bootclasspath that will be used to compile the classes against.

public Path

Returns:

the class path
getClasspath
()

Gets the classpath to be used for this compilation.

public String

Returns:

the compiler.
getCompiler
()

The implementation for this particular task.

public String

Returns:

the compiler.
getCompilerVersion
()

The implementation for this particular task.

public String[]

Returns:

array of command line arguments, guaranteed to be non-null.
getCurrentCompilerArgs
()

Get the additional implementation specific command line arguments.

public boolean

Returns:

the debug flag
getDebug
()

Gets the debug flag.

public String

Returns:

value of debugLevel.
getDebugLevel
()

Get the value of debugLevel.

public boolean

Returns:

the depend flag
getDepend
()

Gets the depend flag.

public boolean

Returns:

the deprecation flag
getDeprecation
()

Gets the deprecation flag.

public File

Returns:

the destination directory
getDestdir
()

Gets the destination directory into which the java source files should be compiled.

public String

Returns:

the source file encoding name
getEncoding
()

Gets the java source file encoding name.

public String

Returns:

the name of the java executable
getExecutable
()

The value of the executable attribute, if any.

public Path

Returns:

the extension directories as a path
getExtdirs
()

Gets the extension directories that will be used during the compilation.

public boolean

Returns:

the failonerror flag
getFailonerror
()

Gets the failonerror flag.

public File[]

Returns:

the list of files as an array
getFileList
()

Gets the list of files to be compiled.

private static int

Returns:

return the index of an enclosing brace of the group or -1 if not found
getGroupEndIndex
(final CharSequence
the element to find the enclosing brace in
element
,
final int
the index of the opening brace.
start
)

Finds the index of an enclosing brace of the group.

public boolean

Returns:

whether or not the ant classpath is to be included in the classpath
getIncludeantruntime
()

Gets whether or not the ant classpath is to be included in the classpath.

public boolean

Returns:

the includejavaruntime attribute
getIncludejavaruntime
()

Gets whether or not the java runtime should be included in this task's classpath.

public String

Returns:

the name of the javac executable
getJavacExecutable
()

The name of the javac executable to use in fork-mode.

public boolean

Returns:

the listfiles flag
getListfiles
()

Get the listfiles flag.

public String

Returns:

the memoryInitialSize flag
getMemoryInitialSize
()

Gets the memoryInitialSize flag.

public String

Returns:

the memoryMaximumSize flag
getMemoryMaximumSize
()

Gets the memoryMaximumSize flag.

public Path

Returns:

the modulepath
getModulepath
()

Gets the modulepath to be used for this compilation.

public Path

Returns:

the modulesourcepath
getModulesourcepath
()

Gets the modulesourcepath to be used for this compilation.

public File

Returns:

where to place generated native header files
getNativeHeaderDir
()

Gets the destination directory into which the generated native header files should be placed.

public boolean

Returns:

true if the -nowarn option should be used
getNowarn
()

Should the -nowarn option be used.

public boolean

Returns:

the optimize flag
getOptimize
()

Gets the optimize flag.

public String

Returns:

the value of the release attribute
getRelease
()

Gets the version to use for the --release switch that combines source, target and setting the bootclasspath.

public String

Returns:

value of source.
getSource
()

Get the value of source.

public Path

Returns:

the source path
getSourcepath
()

Gets the sourcepath to be used for this compilation.

public Path

Returns:

the source directories as a path
getSrcdir
()

Gets the source dirs to find the source java files.

protected String

Returns:

the executable name of the java compiler
getSystemJavac
()

public String

Returns:

the target VM
getTarget
()

Gets the target VM that the classes will be compiled for.

public boolean

Returns:

true if compilation succeeded, or was not necessary, false if the compilation failed.
getTaskSuccess
()

Get the result of the javac task (success or failure).

public File

Returns:

the temporary directory
getTempdir
()

Where Ant should place temporary files.

public Path

Returns:

the upgrademodulepath
getUpgrademodulepath
()

Gets the upgrademodulepath to be used for this compilation.

public boolean

Returns:

the verbose flag
getVerbose
()

Gets the verbose flag.

private static boolean

Returns:

true if the path is non null and non empty.
hasPath
(final Path
to be checked
path
)

Checks if a path exists and is non empty.

public boolean

Returns:

true if this is a forked invocation
isForkedJavac
()

Is this a forked invocation of JDK's javac?

public boolean

Returns:

the value.
isIncludeDestClasses
()

Get the value of the includeDestClasses property.

protected boolean

Returns:

true if compilerImpl is "modern", "classic", "javac1.1", "javac1.2", "javac1.3", "javac1.4", "javac1.5", "javac1.6", "javac1.7", "javac1.8", "javac1.9", "javac9" or "javac10+".
isJdkCompiler
(final String
the name of the compiler implementation
compilerImpl
)

Is the compiler implementation a jdk compiler

private void
lookForPackageInfos(final File srcDir, final File[] newFiles)

protected Path

Returns:

a nested src element.
recreateSrc
()

Recreate src.

protected void
resetFileLists()

Clear the list of files to be compiled and copied..

private static Collection<? extends CharSequence>

Returns:

the possible alternatives
resolveGroup
(final CharSequence
the group to resolve
group
)

Resolves the group to alternatives.

private static Map<String, Collection<File>>

Returns:

a mapping from module name to module source roots
resolveModuleSourcePathElement
(final File
the project directory
projectDir
,
final String
the modulesourcepath elemement
element
)

Resolves the modulesourcepath element possibly containing groups and module marks to module names and source roots.

protected void
scanDir(final File
The source directory
srcDir
,
final File
The destination directory
destDir
,
final String[]
An array of filenames
files
)

Scans the directory looking for source files to be compiled.

public void
setBootclasspath(final Path
a path to use as a boot class path (may be more than one)
bootclasspath
)

Sets the bootclasspath that will be used to compile the classes against.

public void
setBootClasspathRef(final Reference
a reference to a classpath
r
)

Adds a reference to a classpath defined elsewhere.

public void
setClasspath(final Path
an Ant Path object containing the compilation classpath.
classpath
)

Set the classpath to be used for this compilation.

public void
setClasspathRef(final Reference
a reference to a classpath
r
)

Adds a reference to a classpath defined elsewhere.

public void
setCompiler(final String
the name of the compiler
compiler
)

Choose the implementation for this particular task.

public void
setCreateMissingPackageInfoClass(final boolean
boolean
b
)

Whether package-info.class files will be created by Ant matching package-info.java files that have been compiled but didn't create class files themselves.

public void
setDebug(final boolean
if true compile with debug information
debug
)

Indicates whether source should be compiled with debug information; defaults to off.

public void
setDebugLevel(final String
Value to assign to debugLevel.
v
)

Keyword list to be appended to the -g command-line switch.

public void
setDepend(final boolean
if true enable dependency-tracking
depend
)

Enables dependency-tracking for compilers that support this (jikes and classic).

public void
setDeprecation(final boolean
if true turn on deprecation information
deprecation
)

Indicates whether source should be compiled with deprecation information; defaults to off.

public void
setDestdir(final File
the destination director
destDir
)

Set the destination directory into which the Java source files should be compiled.

public void
setEncoding(final String
the source file encoding
encoding
)

Set the Java source file encoding name.

public void
setErrorProperty(final String
the property name to use.
errorProperty
)

The property to set on compilation failure.

public void
setExecutable(final String
the name of the executable
forkExec
)

Sets the name of the javac executable.

public void
setExtdirs(final Path
a path
extdirs
)

Sets the extension directories that will be used during the compilation.

public void
setFailonerror(final boolean
if true halt the build on failure
fail
)

Indicates whether the build will continue even if there are compilation errors; defaults to true.

public void
setFork(final boolean
"true|false|on|off|yes|no"
f
)

If true, forks the javac compiler.

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

If true, includes Ant's own classpath in the classpath.

public void
setIncludeDestClasses(final boolean
the value to use.
includeDestClasses
)

This property controls whether to include the destination classes directory in the classpath given to the compiler.

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

If true, includes the Java runtime libraries in the classpath.

public void
setListfiles(final boolean
if true list the source files
list
)

If true, list the source files being handed off to the compiler.

public void
setMemoryInitialSize(final String
string to pass to VM
memoryInitialSize
)

The initial size of the memory for the underlying VM if javac is run externally; ignored otherwise.

public void
setMemoryMaximumSize(final String
string to pass to VM
memoryMaximumSize
)

The maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise.

public void
setModulepath(final Path
an Ant Path object containing the modulepath.
mp
)

Set the modulepath to be used for this compilation.

public void
setModulepathRef(final Reference
a reference to a modulepath
r
)

Adds a reference to a modulepath defined elsewhere.

public void
setModulesourcepath(final Path
the modulesourcepath
msp
)

Set the modulesourcepath to be used for this compilation.

public void
setModulesourcepathRef(final Reference
a reference to a modulesourcepath
r
)

Adds a reference to a modulesourcepath defined elsewhere.

public void
setNativeHeaderDir(final File
where to place generated native header files
nhDir
)

Set the destination directory into which the generated native header files should be placed.

public void
setNowarn(final boolean
if true, enable the -nowarn option
flag
)

If true, enables the -nowarn option.

public void
setOptimize(final boolean
if true compile with optimization enabled
optimize
)

If true, compiles with optimization enabled.

public void
setProceed(final boolean
inverse of failoferror
proceed
)

public void
setRelease(final String
the value of the release attribute
release
)

Sets the version to use for the --release switch that combines source, target and setting the bootclasspath.

public void
setSource(final String
Value to assign to source.
v
)

Value of the -source command-line switch; will be ignored by all implementations except modern, jikes and gcj (gcj uses -fsource).

public void
setSourcepath(final Path
the source path
sourcepath
)

Set the sourcepath to be used for this compilation.

public void
setSourcepathRef(final Reference
a reference to a source path
r
)

Adds a reference to a source path defined elsewhere.

public void
setSrcdir(final Path
the source directories as a path
srcDir
)

Set the source directories to find the source Java files.

public void
setTarget(final String
the target VM
target
)

Sets the target VM that the classes will be compiled for.

public void
setTempdir(final File
the temporary directory
tmpDir
)

Where Ant should place temporary files.

public void
setUpdatedProperty(final String
the property name to use.
updatedProperty
)

The property to set on compilation success.

public void
setUpgrademodulepath(final Path
an Ant Path object containing the upgrademodulepath.
ump
)

Set the upgrademodulepath to be used for this compilation.

public void
setUpgrademodulepathRef(final Reference
a reference to an upgrademodulepath
r
)

Adds a reference to the upgrademodulepath defined elsewhere.

public void
setVerbose(final boolean
if true, asks the compiler for verbose output
verbose
)

If true, asks the compiler for verbose output.

Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
addaddAndaddContainsaddContainsRegexpaddCustomaddDateaddDependaddDepthaddDifferentaddFilenameaddMajorityaddModifiedaddNoneaddNotaddOraddPresentaddSelectoraddSizeaddTypeappendSelectorcreateExcludecreateExcludesFilecreateIncludecreateIncludesFilecreatePatternSetgetDirectoryScannergetImplicitFileSetgetSelectorshasSelectorsselectorCountselectorElementssetCaseSensitivesetDefaultexcludessetExcludessetExcludesfilesetFollowSymlinkssetIncludessetIncludesfilesetProjectXsetIgnoreXsetItems