A configuration that is the result of
resolution or resolution with
service binding .
A configuration encapsulates the readability graph that is the output of resolution. A readability graph is a directed graph whose vertices are of type ResolvedModule
and the edges represent the readability amongst the modules. Configuration
defines the modules()
method to get the set of resolved modules in the graph. ResolvedModule
defines the reads()
method to get the set of modules that a resolved module reads. The modules that are read may be in the same configuration or may be in parent
configurations.
Configuration defines the resolve
method to resolve a collection of root modules, and the resolveAndBind
method to do resolution with service binding. There are instance and static variants of both methods. The instance methods create a configuration with the receiver as the parent configuration. The static methods are for more advanced cases where there can be more than one parent configuration.
Each layer
of modules in the Java virtual machine is created from a configuration. The configuration for the boot
layer is obtained by invoking ModuleLayer.boot().configuration()
. The configuration for the boot layer will often be the parent when creating new configurations.
Example
The following example uses the resolve
method to resolve a module named myapp with the configuration for the boot layer as the parent configuration. It prints the name of each resolved module and the names of the modules that each module reads.
ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
cf.modules().forEach(m -> {
System.out.format("%s -> %s%n",
m.name(),
m.reads().stream()
.map(ResolvedModule::name)
.collect(Collectors.joining(", ")));
});