CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 294
ClassGraph API
See also the code examples page.
-
Create a
new ClassGraph()
instance, and configure it for scanning:- Optionally call
.verbose()
to enable verbose logging to stderr. - Enable classfile scanning, if you want to scan classes -- in the simplest case, call
.enableAllInfo()
to enable the scanning of classes, methods, fields, and annotations. - Call
.acceptPackages(String... packages)
to accept specific packages to scan, or.acceptPaths(String... paths)
if you only want to scan resources and not classes. If you don't call either of these methods, then all packages or paths will be scanned.
- Optionally call
-
Start the scan, by calling
.scan()
, to produce aScanResult
object.💡 The
ScanResult
should be assigned in a try-with-resources block or equivalent. SeeScanResult
lifecycle. -
Query the
ScanResult
object: (theScanResult
object can be queried repeatedly without re-running the scan)-
For class scan results: Call methods such as
.getAllClasses()
,.getAllInterfaces()
etc. to getClassInfoList
lists ofClassInfo
objects for classes of interest- Query the
ClassInfo
objects for class properties or class relationships of interest.- Call
ClassInfo#getMethodInfo()
to get info on the methods of the class as aMethodInfoList
ofMethodInfo
objects.- Call
MethodInfo#getMethodParameterInfo()
to get info on the parameters of a method as an array ofMethodParameterInfo
objects, one per parameter. - Call
MethodInfo#getAnnotationInfo()
to get the annotations on a method as anAnnotationInfoList
ofAnnotationInfo
objects.
- Call
- Call
ClassInfo#getFieldInfo()
to get info on the fields of a class as aFieldInfoList
ofFieldInfo
objects.- Call
FieldInfo#getAnnotationInfo()
to the annotations on a field as anAnnotationInfoList
ofAnnotationInfo
objects.
- Call
- Call
ClassInfo#getAnnotationInfo()
to get the annotations on a class as anAnnotationInfoList
ofAnnotationInfo
objects.
- Call
-
ClassInfoList
lists can be filtered using.filter(predicateFunction)
or combined using.union(ClassInfoList... others)
,.intersect(ClassInfoList... others)
, or.exclude(ClassInfoList other)
, to return a newClassInfoList
representing the predicate-filtered subset, union, intersection or set difference respectively.
- Query the
-
And/or for resource scan results: Call methods such as
.getAllResources()
,.getResourcesWithPath(path)
,.getResourcesWithExtension(ext)
etc. to getResourceList
lists ofResource
(file) objects matching a given path or filename pattern.- Call methods
ResourceList#forEachByteArray(ByteArrayConsumer)
and similar functions to open the content of eachResource
object as aByteBuffer
orInputStream
, or read the complete contents into abyte[]
array, then pass the buffer, stream or array to a consumer method, closing the buffer or stream when the consumer exits.
- Call methods
-
For class scan results: Call methods such as
You can scan either at runtime (the normal usecase), or at build time (for faster startup speed, or to support Android, since it does not use the standard Java bytecode format).
See the code examples page for specific examples of how to use the ClassGraph API.
- Configuring the
ClassGraph
instance - Starting the scan
- Processing the result of the scan:
-
Classes:
-
Classes
-
ClassInfo
- (The class metadata class. Use
ClassInfo
objects to obtain references toAnnotationInfo
,MethodInfo
,MethodParameterInfo
orFieldInfo
objects.)
- (The class metadata class. Use
ClassInfoList
-
-
Methods
-
MethodInfo
- (The method metadata class. Use
MethodInfo
objects to obtain references toMethodParameterInfo
objects, and/orAnnotationInfo
objects for method annotations.)
- (The method metadata class. Use
-
MethodParameterInfo
- (The method parameter metadata class. Use
MethodParameterInfo
objects to obtain references toAnnotationInfo
objects for method parameter annotations.)
- (The method parameter metadata class. Use
MethodInfoList
-
-
Fields
-
FieldInfo
- (The field metadata class. Use
FieldInfo
objects to obtain references toAnnotationInfo
objects for field annotations.)
- (The field metadata class. Use
FieldInfoList
-
-
Annotations
-
AnnotationInfo
- (The annotation metadata class. Use
AnnotationInfo
objects to obtain references toAnnotationParameterValue
objects for parameter values for specific annotation instances.)
- (The annotation metadata class. Use
AnnotationParameterValue
AnnotationEnumValue
AnnotationClassRef
AnnotationInfoList
-
- Type signatures
- Packages:
- Modules:
-
Classes
-
Resources:
-
Resource
- (The main metadata class for resource files encountered in accepted packages or paths during a scan.)
ResourceList
-
- Obtaining module references
ClassGraph version 4 is a major upgrade over the previous version, FastClasspathScanner version 3, and there were a number of major API changes between FastClasspathScanner and ClassGraph. See here for information on porting FastClasspathScanner v3 code to the ClassGraph v4 API, and for info on how to obtain the older FastClasspathScanner version 3 documentation.