ModuleFinder is used to find modules during
resolution or
service binding.
A ModuleFinder can only find one module with a given name. A
ModuleFinder that finds modules in a sequence of directories, for
example, will locate the first occurrence of a module of a given name and
will ignore other modules of that name that appear in directories later in
the sequence.
Example usage:
Path dir1 = ..., dir2 = ..., dir3 = ...;
ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
Optional<ModuleReference> omref = finder.find("jdk.foo");
omref.ifPresent(mref -> ... );
The find and findAll methods
defined here can fail for several reasons. These include I/O errors, errors
detected parsing a module descriptor (module-info.class), or in the
case of ModuleFinder returned by ModuleFinder., that
two or more modules with the same name are found in a directory.
When an error is detected then these methods throw FindException with an appropriate cause.
The behavior of a ModuleFinder after a FindException is
thrown is undefined. For example, invoking find after an exception
is thrown may or may not scan the same modules that lead to the exception.
It is recommended that a module finder be discarded after an exception is
thrown.
A ModuleFinder is not required to be thread safe.
| Modifier and Type | Method and Description |
|---|---|
| public static ModuleFinder | Returns: AModuleFinder that composes a sequence of module findersThe array of module finders finders)Returns a module finder that is composed from a sequence of zero or more module finders. |
| public Optional | |
| public Set | Returns: The set of all module references that this finder locatesReturns the set of all module references that this finder can locate. |
| public static ModuleFinder | Returns: AModuleFinder that locates modules on the file systemA possibly-empty array of paths to directories of modules
or paths to packaged or exploded modules entries)Returns a module finder that locates modules on the file system by searching a sequence of directories and/or packaged modules. |
| public static ModuleFinder | Returns: AModuleFinder that locates the system modulesReturns a module finder that locates the system modules. |
| compose | back to summary |
|---|---|
| public static ModuleFinder compose(ModuleFinder... finders) Returns a module finder that is composed from a sequence of zero or more
module finders. The When locating modules then any exceptions or errors thrown by the
| |
| find | back to summary |
|---|---|
| public Optional Finds a reference to a module of a given name. A
| |
| findAll | back to summary |
|---|---|
| public Set Returns the set of all module references that this finder can locate. A API Note This is important to have for methods such as
| |
| of | back to summary |
|---|---|
| public static ModuleFinder of(Path... entries) Returns a module finder that locates modules on the file system by searching a sequence of directories and/or packaged modules. Each element in the given array is one of:
If an element is a path to a directory of modules then each entry in
the directory is a packaged module or the top-level directory of an
exploded module. It is an error if a directory contains more than one
module with the same name. If an element is a path to a directory, and
that directory contains a file named The module finder returned by this method
supports modules packaged as JAR files. A JAR file with a
If a In addition to JAR files, an implementation may also support modules
that are packaged in other implementation specific module formats. If
an element in the array specified to this method is a path to a directory
of modules then entries in the directory that not recognized as modules
are ignored. If an element in the array is a path to a packaged module
that is not recognized then a As with automatic modules, the contents of a packaged or exploded
module may need to be scanned in order to determine the packages
in the module. Whether hidden files are ignored or not is implementation specific and therefore
not specified. If a Finders created by this method are lazy and do not eagerly check
that the given file paths are directories or packaged modules.
Consequently, the
| |
| ofSystem | back to summary |
|---|---|
| public static ModuleFinder ofSystem() Returns a module finder that locates the system modules. The
system modules are the modules in the Java run-time image.
The module finder will always find
| |