com.sun.source.* packages provide the Compiler Tree API:
an API for accessing the abstract trees (ASTs) representing Java source code
and documentation comments, used by javac, javadoc and related tools.
This module provides the equivalent of command-line access to javac
Tool service provider interfaces (SPIs),
and more flexible access via the
Instances of the tools can be obtained by calling
or the service loader with the name
In addition, instances of
obtained from JavaCompiler can be
JavacTask for access to
lower level aspects of javac, such as the
Abstract Syntax Tree (AST).
This module uses the
FileSystemProvider API to locate file system providers. In particular,
this means that a jar file system provider, such as that in the
jdk.zipfs module, must be available if the compiler is to be able
to read JAR files.
Options and Environment VariablesThe full set of options and environment variables supported by javac is given in the javac Tool Guide. However, there are some restrictions when the compiler is invoked through its API.
-Joption is not supported. Any necessary VM options must be set in the VM used to invoke the API.
IllegalArgumentExceptionwill be thrown if the option is used when invoking the tool through the
JavaCompilerAPI; an error will be reported if the option is used when invoking javac through the
The "classpath wildcard" feature is not supported. The feature is only supported by the native launcher. When invoking the tool through its API, all necessary jar files should be included directly in the
--class-pathoption, or the
CLASSPATHenvironment variable. When invoking the tool through its API, all components of the class path will be taken literally, and will be ignored if there is no matching directory or file. The
-Xlint:pathsoption can be used to generate warnings about missing components.
Argument files (so-called @-files) are not supported. The content of any such files should be included directly in the list of options provided when invoking the tool though this API.
IllegalArgumentExceptionwill be thrown if the option is used when invoking the tool through this API.
The environment variable
JDK_JAVAC_OPTIONSis not supported. Any options defined in the environment variable should be included directly in the list of options provided when invoking the API; any values in the environment variable will be ignored.
Options that are just used to obtain information (such as
--full-version) are not supported.
IllegalArgumentExceptionwill be thrown if any of these options are used when invoking the tool through this API.
- Path-related options depend on the file manager being used
JavaCompiler.getTask(java.io.Writer, javax.tools.JavaFileManager, javax.tools.DiagnosticListener<? super javax.tools.JavaFileObject>, java.lang.Iterable<java.lang.String>, java.lang.Iterable<java.lang.String>, java.lang.Iterable<? extends javax.tools.JavaFileObject>). The "standard" options, such as
--module-path, and so on are available when using the default file manager, or one derived from it. These options may not be available and different options may be available, when using a different file manager.
IllegalArgumentExceptionwill be thrown if any option that is unknown to the tool or the file manager is used when invoking the tool through this API.
CLASSPATHenvironment variable is honored when invoking the compiler through its API, although such use is discouraged. An environment variable cannot be unset once a VM has been started, and so it is recommended to ensure that the environment variable is not set when starting a VM that will be used to invoke the compiler. However, if a value has been set, any such value can be overridden by using the
--class-pathoption when invoking the compiler, or setting
StandardLocation.CLASS_PATHin the file manager when invoking the compiler through the
SuppressWarningsJLS 126.96.36.199 specifies a number of strings that can be used to suppress warnings that may be generated by a Java compiler. In addition, javac also supports other strings that can be used to suppress other kinds of warnings. The following table lists all the strings that can be used with
|String||Suppress Warnings About ...|
|an auxiliary class that is hidden in a source file, and is used from other files|
|use of unnecessary casts|
|issues related to classfile contents|
|use of deprecated items|
|items marked as deprecated in a documentation comment but not
using the |
|division by constant integer |
|empty statement after |
|issues regarding module exports|
|falling through from one case of a |
|possible lossy conversions in compound assignment|
|missing explicit constructors in public and protected classes in exported packages|
|module system related issues|
|issues regarding module opens|
|issues regarding method overloads|
|issues regarding method overrides|
|invalid path elements on the command line|
|use of preview language features|
|use of raw types|
|use of API that has been marked for removal|
|use of automatic modules in the |
|automatic modules in |
|accessing a static member using an instance|
|unnecessary use of the |
|synchronization attempts on instances of value-based classes|
|inconsistent white space characters in text block indentation|
|superclass constructor leaking |
|issues relating to use of |
|potentially unsafe vararg methods|
|accessibility issues found in documentation comments|
|all issues found in documentation comments|
|HTML issues found in documentation comments|
|missing items in documentation comments|
|reference issues found in documentation comments|
|syntax issues found in documentation comments|
- Tool Guides:
PackagesPackageDescriptionProvides interfaces to represent documentation comments as abstract syntax trees (AST).Provides interfaces to represent source code as abstract syntax trees (AST).Provides utilities for operations on abstract syntax trees (AST).This package provides a legacy entry point for the javac tool.
ModulesModifierModuleDescriptiontransitiveDefines the Language Model, Annotation Processing, and Java Compiler APIs.
ServicesTypeDescriptionInterface to invoke Java programming language compilers from programs.Common interface for tools that can be invoked from a program.Use
ToolProvider.findFirst("javac")to obtain an instance of a
ToolProviderthat provides the equivalent of command-line access to the