Repository navigation
ModuleInfo API
See also the ClassGraph API overview.
Holds information about a named module encountered during scanning. A directory or jar on the traditional classpath is in the unnamed module at runtime, but it is still listed here, under the name it declares through module-info.class or the Automatic-Module-Name manifest attribute. A jar that declares neither is listed under the automatic module name that the module system would derive from its filename, if that is a legal module name; a directory that declares neither is not listed. Obtain these objects by calling ScanResult#getModuleInfo(moduleName) or ScanResult#getModuleInfo().
There is one ModuleInfo for each classpath element that holds a module, so two classpath elements with the same module name (for example foo-1.0.jar and foo-2.0.jar, which both derive the name foo) each have their own ModuleInfo, with their own location. ScanResult#getModuleInfo() then lists the name twice, and ScanResult#getModuleInfo(moduleName) returns the first one in scan order, as the module system would resolve it. Modules on the module path come before the traditional classpath in the scan order.
🛑 A module resolved in a module layer is only scanned if a module source was enabled before the scan:
ClassGraph#enableNonSystemModules()or#enableSystemModules(). A directory or jar on the traditional classpath can also produce aModuleInfowhen classpath scanning is enabled. Nothing is scanned by default. See Saying what to scan.
-
Properties: (Needs
.enableClassInfo()before.scan(). Call.ignoreClassVisibility()as well to get the modules of non-public classes.)-
.getName()returns the non-empty name of the module as aString. ClassGraph does not create aModuleInfofor the unnamed module. -
.getLocationURI()returns the location of the module as aURI, or null for modules whose location is unknown. -
.getModuleReference()returns thejava.lang.module.ModuleReferencefor the module, or null if the name came from a directory or jar on the traditional classpath -- whether it declared the name or the name was derived from the jar's filename -- rather than from a module resolved in aModuleLayer.
-
-
Classes:
-
.getClassInfo()returns aClassInfoListofClassInfoobjects for all classes found in this module. Rejected classes are not listed, and neither are external classes unlessClassGraph#enableExternalClasses()was called before the scan. -
.getClassInfo(String className)returns theClassInfoobject for the named class in this module, or null if the class was not found in this module.
-
-
Packages:
-
.getPackageInfo()returns aPackageInfoListofPackageInfoobjects for all packages that are members of this module. -
.getPackageInfo(String packageName)returns thePackageInfoobject for the package of the given name in this module, or null if the package was not found in this module. ThePackageInfoobject is shared by the whole scan: it is the object thatScanResult#getPackageInfo(packageName)returns. So if the package is split across modules (which is allowed on the traditional classpath), its.getClassInfo()lists the package's classes in every module. To list only this module's classes in the package, callmoduleInfo.getClassInfo().filter(ci -> ci.getPackageName().equals(packageName)).
-
-
Annotations: (module annotations are the annotations on the
module-info.javamodule descriptor)-
.getAllAnnotationInfo()/.getDirectAnnotationInfo()returns the annotations on this module as anAnnotationInfoList. TheAllform also includes meta-annotations -- the annotations on the module's own annotations, transitively. -
.hasAnnotation(String annotationName | Class<? extends Annotation> annotationClass)returnstrueif the module has the given annotation. -
.getAllAnnotationInfo(String annotationName | Class<? extends Annotation> annotationClass)/.getDirectAnnotationInfo(...)returns theAnnotationInfoobject for the given non-@Repeatablemodule annotation, or null if none. -
.getAllAnnotationInfoRepeatable(String annotationName | Class<? extends Annotation> annotationClass)/.getDirectAnnotationInfoRepeatable(...)returns theAnnotationInfoobjects for the given@Repeatablemodule annotation, as anAnnotationInfoList, or the empty list if none.
-
An unmodifiable List<ModuleInfo>, whether returned by ClassGraph or constructed from a completed collection, with the following convenience methods:
-
.asMap()returns theModuleInfoListas aMap<String, ModuleInfo>mapping the module name to the correspondingModuleInfoobject, sorted by module name. If the list holds more than one module with the same name, the name maps to the one that.get(String)returns. -
.getNames()returns a list of the names of the modules in this list as aList<String>. -
.getAsStrings()returns a list of the result of calling.toString()on eachModuleInfoobject in this list, producing aList<String>ofStringrepresentations of each module, of the formmodule <name>. -
.containsName(String moduleName)returnstrueif a module of the given name is contained in this list. -
.get(String moduleName)returns the firstModuleInfoobject in this list with the requested name, if present, otherwise returns null. For the list returned byScanResult#getModuleInfo(), this is the same object thatScanResult#getModuleInfo(moduleName)returns. -
.filter(Predicate<ModuleInfo> filter)returns aModuleInfoListthat is a subset of the original list, obtained by applying the given predicate to eachModuleInfoobject in the list.
The module path itself -- the --module-path, --add-modules, --patch-module, --add-exports, --add-opens and --add-reads arguments the JVM was launched with -- is described by ModulePathInfo, which lives in the classpath-finding library. See ModulePathInfo.