ModuleRef API
Luke Hutchison edited this page Jun 6, 2020
·
1 revision
See also the ClassGraph API overview.
Two reflection-based wrapper classes are provided for accessing modules, ModuleRef
which proxies calls to ModuleReference
, and ModuleReaderProxy
which proxies calls to ModuleReader
, for backwards compatibility when compiling code for JDK 7 and JDK 8. These proxy classes provide some additional convenience methods over the JDK versions they wrap.
You can get a list of visible modules in several ways:
List<ModuleRef> modules =
new ClassGraph()
.enableSystemPackages() // Optional, to return system modules
.getModules();
List<ModuleRef> modules = scanResult.getModules()
(3) Get a ModuleRef
from a ModuleInfo
object
ModuleInfo myModuleInfo = scanResult.getModuleInfo("my.module");
if (myModuleInfo != null) {
ModuleRef moduleRef = myModuleInfo.getModuleRef();
// ...
}
Holds a reference to a module. This is a JDK 7/8 compatible, introspection-based wrapper for JPMS' ModuleReference
class.
-
.getName()
returns the name of the module as aString
. -
.getRawVersion()
returns the raw version of the module as aString
, or null if there was no version information available. -
.getLocation()
returns the location of the module as aURI
. -
.getLocationStr()
returns the location of the module as a URI string. -
.getPackages()
returns the packages in the module as aList<String>
. (Does not include non-package directories.) -
.isSystemModule()
returns true if this is a system module (i.e.java.*
,jdk.*
,javax.*
,oracle.*
, etc.) -
.open()
returns aModuleReaderProxy
that can be used to read from the module. Make sure you call.close()
on theModuleReaderProxy
when you have finished. -
.getReference()
gets the wrapped JPMSModuleReference
. -
.getLayer()
gets theModuleLayer
of the module. -
.getDescriptor()
gets theModuleDescriptor
for the module.
Holds a reference to a module reader. This is an introspection-based wrapper for JPMS' ModuleReader
class. This wrapper gives backwards compatibility with JDK 7 and JDK 8.
-
.list()
returns the resource paths in the module as aList<String>
. -
.open(String path)
opens the resource with the given path as anInputStream
. Make sure you callclose()
on thisInputStream
when you have finished. -
.read(String path)
opens the resource with the given path as aByteBuffer
. Make sure you call.release(byteBuffer)
when you have finished. -
.release(ByteBuffer byteBuffer)
releases aByteBuffer
after it was allocated by calling.read(String path)
. -
.close()
closes theModuleReader
. Make sure you call this method when you have finished with theModuleReaderProxy
.