Module java.base
Package java.lang.module

Interface ModuleFinder


public interfaceModuleFinder
A finder of modules. AModuleFinder is used to find modules duringresolution orservice binding.

AModuleFinder can only find one module with a given name. AModuleFinder 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 -> ... );

Thefind andfindAll 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 ofModuleFinder returned byModuleFinder.of, that two or more modules with the same name are found in a directory. When an error is detected then these methods throwFindException with an appropriatecause. The behavior of aModuleFinder after aFindException is thrown is undefined. For example, invokingfind 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.

AModuleFinder is not required to be thread safe.

Since:
9