APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.tools.javac.launcher

public final Class SourceLauncher

extends Object
Class Inheritance
Imports
com.sun.tools.javac.resources.LauncherProperties.Errors, java.io.OutputStreamWriter, .PrintStream, .PrintWriter, java.lang.reflect.Constructor, .InvocationTargetException, .Method, .Modifier, java.nio.file.Files, .InvalidPathException, .Path, .Paths, java.util.Arrays, jdk.internal.misc.MethodFinder, .VM, jdk.internal.module.Modules

Compiles a source file, and executes the main method it contains.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Field Summary

Modifier and TypeField and Description
private final PrintWriter
out

Stream for reporting errors, such as compilation errors.

Constructor Summary

AccessConstructor and Description
public
SourceLauncher(PrintStream
the stream
out
)

Creates an instance of this class, providing a stream to which to report any errors.

public
SourceLauncher(PrintWriter
the stream
out
)

Creates an instance of this class, providing a stream to which to report any errors.

Method Summary

Modifier and TypeMethod and Description
private Class<?>
execute(MemoryContext
the context for the class to be executed
context
,
String[]
the arguments for the main method
mainArgs
)

Invokes the main method of a program class, using a class loader that will load recently compiled classes from memory.

private Path

Returns:

the path, as given in the array of args
getFile
(String[]
the array
args
)

Returns the path for the filename found in the first of an array of arguments.

public static void
main(String...
the arguments
args
)

Compiles a source file, and executes the main method it contains.

private static void
openPackageTo(Module module, String packageName, Module target)

public Result
run(String[]
the runtime arguments
runtimeArgs
,
String[]
the arguments
args
)

Compiles a source file, and executes the main method it contains.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

outback to summary
private final PrintWriter out

Stream for reporting errors, such as compilation errors.

Constructor Detail

SourceLauncherback to summary
public SourceLauncher(PrintStream out)

Creates an instance of this class, providing a stream to which to report any errors.

Parameters
out:PrintStream

the stream

SourceLauncherback to summary
public SourceLauncher(PrintWriter out)

Creates an instance of this class, providing a stream to which to report any errors.

Parameters
out:PrintWriter

the stream

Method Detail

executeback to summary
private Class<?> execute(MemoryContext context, String[] mainArgs) throws Fault, InvocationTargetException

Invokes the main method of a program class, using a class loader that will load recently compiled classes from memory.

Parameters
context:MemoryContext

the context for the class to be executed

mainArgs:String[]

the arguments for the main method

Exceptions
Fault:
if there is a problem finding or invoking the main method
InvocationTargetException:
if the main method throws an exception
getFileback to summary
private Path getFile(String[] args) throws Fault

Returns the path for the filename found in the first of an array of arguments.

Parameters
args:String[]

the array

Returns:Path

the path, as given in the array of args

Exceptions
Fault:
if there is a problem determining the path, or if the file does not exist
mainback to summary
public static void main(String... args) throws Throwable

Compiles a source file, and executes the main method it contains.

This is normally invoked from the Java launcher, either when the --source option is used, or when the first argument that is not part of a runtime option ends in .java.

The first entry in the args array is the source file to be compiled and run; all subsequent entries are passed as arguments to the main method of the first class found in the file.

If any problem occurs before executing the main class, it will be reported to the standard error stream, and the JVM will be terminated by calling System.exit with a non-zero return code.

Parameters
args:String[]

the arguments

Exceptions
Throwable:
if the main method throws an exception
openPackageToback to summary
private static void openPackageTo(Module module, String packageName, Module target)
runback to summary
public Result run(String[] runtimeArgs, String[] args) throws Fault, InvocationTargetException

Compiles a source file, and executes the main method it contains.

The first entry in the args array is the source file to be compiled and run; all subsequent entries are passed as arguments to the main method of the first class found in the file.

Options for javac are obtained by filtering the runtime arguments.

If the main method throws an exception, it will be propagated in an InvocationTargetException. In that case, the stack trace of the target exception will be truncated such that the main method will be the last entry on the stack. In other words, the stack frames leading up to the invocation of the main method will be removed.

Parameters
runtimeArgs:String[]

the runtime arguments

args:String[]

the arguments

Exceptions
Fault:
if a problem is detected before the main method can be executed
InvocationTargetException:
if the main method throws an exception