java.lang.Object javax.tools.ToolProvider
public class ToolProvider
Provides methods for locating tool providers, for example, providers of Java compilers. This class complements the functionality of
ServiceLoader
.
A simple mechanism for looking up tool providers. A
tool
is a subinterface of Tool. Tool providers may be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Tools may also be made available by adding them to the applet or application class path or by some other platform-specific means.
In this lookup mechanism a tool is represented by an interface. A provider of a given tool contains one or more concrete classes that extend this
tool interface
with data and code specific to the provider. The only requirement enforced here is that provider classes must have a zero-argument constructor so that they may be instantiated during lookup.
If a particular concrete provider class is named in more than one configuration file, or is named in the same configuration file more than once, then the duplicates will be ignored. The configuration file naming a particular provider need not be in the same jar file or other distribution unit as the provider itself. The provider must be accessible from the same class loader that was initially queried to locate the configuration file; note that this is not necessarily the class loader that found the file.
For example, if
com.vendor.Tool
is a provider of the
JavaCompilerTool
tool then its jar file would contain the file
META-INF/services/javax.tools.JavaCompilerTool
. This file would contain the single line:
com.vendor.Tool
Method Summary | ||
---|---|---|
static
JavaCompiler
|
getSystemJavaCompiler
Gets the Java compiler provided with |
|
static ClassLoader |
getSystemToolClassLoader
()
Returns the class loader for tools provided with this platform. |
|
|
|
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Method Detail |
---|
public static JavaCompilerJavaCompilerToolgetSystemJavaCompilerdefaultJavaCompiler()
public static ClassLoader<T extendsTool>Iterable<T>getSystemToolClassLoaderinstalledTools()(Class<T> tool) throwsIllegalArgumentException
If the extension class loader cannot be found then the system class loader is used; if there is no system class loader then the bootstrap class loader is used.
For example, to locate all available Java compilers, use this code:
for (JavaCompilerTool compiler : installedTools(JavaCompilerTool.class)) System.out.format("Found compiler %s%n", compiler.getClass());