Class LayerBootstrap
ModuleLayer graph and handing off to the real application.
Applications never invoke this class themselves — it is what the tentackle-jlink-maven-plugin's
generated launcher script runs instead of the real main class whenever <layers> are configured
(see the jlinkpackage.md and layers.md documentation), and what an IDE run/debug configuration
points at to run an application with isolated layers locally.
main(String[]) reads a LayerGraphSpec from a properties file (see LAYERS_PROPERTY),
builds the layer graph via ModuleLayerBuilder, sets the leaf layer's classloader as the thread context
classloader — which is what makes every existing, layer-unaware ServiceFactory.getServiceFinder()
call transparently resolve services from within the leaf layer — and then reflectively invokes the real
application's main(String[]) method.
Relative layer directories in the properties file are resolved against the directory given by
LAYERS_BASEDIR_PROPERTY, or against the current working directory if that property is not set
— never against the directory of the properties file.
- Author:
- harald
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault location of the layers configuration file, relative to the current working directory.static final StringSystem property naming the base directory relative layer directories are resolved against.
Defaults to the current working directory.static final StringSystem property naming the layers configuration file.
Resolved relative to the current working directory if not absolute. -
Method Summary
Modifier and TypeMethodDescriptionstatic ModuleLayerGets a layer built by this bootstrap, by name.
This is how application code reaches a layer other than its own leaf layer — e.g., one pinning a specific version of a dependency — typically to then resolve a service from it viaServiceFactory.getServiceFinder(ModuleLayer, String).static Map<String, ModuleLayer> Gets all layers built by this bootstrap, keyed by name.static voidBuilds the configured module layer graph and invokes the real application's main method.
-
Field Details
-
LAYERS_PROPERTY
System property naming the layers configuration file.
Resolved relative to the current working directory if not absolute.- See Also:
-
DEFAULT_LAYERS_FILE
Default location of the layers configuration file, relative to the current working directory.- See Also:
-
LAYERS_BASEDIR_PROPERTY
System property naming the base directory relative layer directories are resolved against.
Defaults to the current working directory. Necessary whenever the launcher cannot change into the image root first, such as the native launcher of a jpackage installation.- See Also:
-
-
Method Details
-
getLayer
Gets a layer built by this bootstrap, by name.
This is how application code reaches a layer other than its own leaf layer — e.g., one pinning a specific version of a dependency — typically to then resolve a service from it viaServiceFactory.getServiceFinder(ModuleLayer, String). See thelayers.mddocumentation for the full pattern, including why a layer must not have two parent layers that define the same module (for example, two versions of the same library).- Parameters:
name- the layer name, as configured- Returns:
- the layer
- Throws:
TentackleRuntimeException- if no such layer, or called beforemain(String[])has run
-
getLayers
Gets all layers built by this bootstrap, keyed by name.- Returns:
- the layers, empty if
main(String[])has not run yet
-
main
Builds the configured module layer graph and invokes the real application's main method.- Parameters:
args- the application arguments, passed through unchanged- Throws:
Exception- if the layer graph cannot be built or the application's main method fails (the latter wrapped in aTentackleRuntimeException)
-