public class ClassGraph extends Object
Documentation: https://github.com/classgraph/classgraph/wiki
Modifier and Type | Class and Description |
---|---|
static interface |
ClassGraph.ClasspathElementFilter
Add a classpath element filter.
|
static interface |
ClassGraph.ClasspathElementURLFilter
Add a classpath element URL filter.
|
static interface |
ClassGraph.FailureHandler
A callback used to handle failure during an asynchronous scan.
|
static interface |
ClassGraph.ScanResultProcessor
A callback used to process the result of a successful asynchronous scan.
|
Constructor and Description |
---|
ClassGraph()
Construct a ClassGraph instance.
|
Modifier and Type | Method and Description |
---|---|
ClassGraph |
acceptClasses(String... classNames)
Scan one or more specific classes, without scanning other classes in the same package unless the package is
itself accepted.
|
ClassGraph |
acceptClasspathElementsContainingResourcePath(String... resourcePaths)
Accept classpath elements based on resource paths.
|
ClassGraph |
acceptJars(String... jarLeafNames)
Accept one or more jars.
|
ClassGraph |
acceptLibOrExtJars(String... jarLeafNames)
Accept one or more jars in a JRE/JDK "lib/" or "ext/" directory (these directories are not scanned unless
enableSystemJarsAndModules() is called, by association with the JRE/JDK). |
ClassGraph |
acceptModules(String... moduleNames)
Accept one or more modules for scanning.
|
ClassGraph |
acceptPackages(String... packageNames)
Scan one or more specific packages and their sub-packages.
|
ClassGraph |
acceptPackagesNonRecursive(String... packageNames)
Scan one or more specific packages, without recursively scanning sub-packages unless they are themselves
accepted.
|
ClassGraph |
acceptPaths(String... paths)
Scan one or more specific paths, and their sub-directories or nested paths.
|
ClassGraph |
acceptPathsNonRecursive(String... paths)
Scan one or more specific paths, without recursively scanning sub-directories or nested paths unless they are
themselves accepted.
|
ClassGraph |
addClassLoader(ClassLoader classLoader)
Add a ClassLoader to the list of ClassLoaders to scan.
|
ClassGraph |
addModuleLayer(Object moduleLayer)
Add a ModuleLayer to the list of ModuleLayers to scan.
|
ClassGraph |
blacklistClasses(String... classNames)
Deprecated.
Use
rejectClasses(String...) instead. |
ClassGraph |
blacklistClasspathElementsContainingResourcePath(String... resourcePaths)
Deprecated.
|
ClassGraph |
blacklistJars(String... jarLeafNames)
Deprecated.
Use
rejectJars(String...) instead. |
ClassGraph |
blacklistLibOrExtJars(String... jarLeafNames)
Deprecated.
Use
rejectLibOrExtJars(String...) instead. |
ClassGraph |
blacklistModules(String... moduleNames)
Deprecated.
Use
rejectModules(String...) instead. |
ClassGraph |
blacklistPackages(String... packageNames)
Deprecated.
Use
rejectPackages(String...) instead. |
ClassGraph |
blacklistPaths(String... paths)
Deprecated.
Use
rejectPaths(String...) instead. |
ClassGraph |
disableDirScanning()
Disables the scanning of directories.
|
ClassGraph |
disableJarScanning()
Disables the scanning of jarfiles.
|
ClassGraph |
disableModuleScanning()
Disables the scanning of modules.
|
ClassGraph |
disableNestedJarScanning()
Disables the scanning of nested jarfiles (jarfiles within jarfiles).
|
ClassGraph |
disableRuntimeInvisibleAnnotations()
Causes only runtime visible annotations to be scanned (causes runtime invisible annotations to be ignored).
|
ClassGraph |
enableAllInfo()
Enables the scanning of all classes, fields, methods, annotations, and static final field constant
initializer values, and ignores all visibility modifiers, so that both public and non-public classes, fields
and methods are all scanned.
|
ClassGraph |
enableAnnotationInfo()
Enables the saving of annotation info (for class, field, method and method parameter annotations) during the
scan.
|
ClassGraph |
enableClassInfo()
Enables the scanning of classfiles, producing
ClassInfo objects in the ScanResult . |
ClassGraph |
enableExternalClasses()
Causes ClassGraph to return classes that are not in the accepted packages, but that are directly referred to
by classes within accepted packages as a superclass, implemented interface or annotation.
|
ClassGraph |
enableFieldInfo()
Enables the saving of field info during the scan.
|
ClassGraph |
enableInterClassDependencies()
Enables the determination of inter-class dependencies, which may be read by calling
ClassInfo.getClassDependencies() , ScanResult.getClassDependencyMap() or
ScanResult.getReverseClassDependencyMap() . |
ClassGraph |
enableMemoryMapping()
If true, use a
MappedByteBuffer rather than the FileChannel API to open files, which may be
faster for large classpaths consisting of many large jarfiles, but uses up virtual memory space. |
ClassGraph |
enableMethodInfo()
Enables the saving of method info during the scan.
|
ClassGraph |
enableRealtimeLogging()
Enables logging by calling
verbose() , and then sets the logger to "realtime logging mode", where log
entries are written out immediately to stderr, rather than only after the scan has completed. |
ClassGraph |
enableRemoteJarScanning()
Enable classpath elements to be fetched from remote ("http:"/"https:") URLs (or URLs with custom schemes).
|
ClassGraph |
enableStaticFinalFieldConstantInitializerValues()
Enables the saving of static final field constant initializer values.
|
ClassGraph |
enableSystemJarsAndModules()
Enables the scanning of system packages (
"java.*" , "javax.*" , "javafx.*" ,
"jdk.*" , "oracle.*" , "sun.*" ) -- these are not scanned by default for speed. |
ClassGraph |
enableURLScheme(String scheme)
Enable classpath elements to be fetched from
URL connections with the specified URL scheme (also
works for any custom URL schemes that have been defined, as long as they have more than two characters, in
order to not conflict with Windows drive letters). |
ClassGraph |
filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)
Add a classpath element filter.
|
ClassGraph |
filterClasspathElementsByURL(ClassGraph.ClasspathElementURLFilter classpathElementURLFilter)
Add a classpath element filter.
|
String |
getClasspath()
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order, in the form of a classpath path string.
|
List<File> |
getClasspathFiles()
Returns the list of all unique File objects representing directories or zip/jarfiles on the classpath, in
classloader resolution order.
|
List<URI> |
getClasspathURIs()
Returns the ordered list of all unique
URI objects representing directory/jar classpath elements and
modules. |
List<URL> |
getClasspathURLs()
Returns the ordered list of all unique
URL objects representing directory/jar classpath elements and
modules. |
ModulePathInfo |
getModulePathInfo()
Get the module path info provided on the commandline with
--module-path , --add-modules ,
--patch-module , --add-exports , --add-opens , and --add-reads . |
List<ModuleRef> |
getModules()
Returns
ModuleRef references for all the visible modules. |
static String |
getVersion()
Get the version number of ClassGraph.
|
ClassGraph |
ignoreClassVisibility()
Causes class visibility to be ignored, enabling private, package-private and protected classes to be scanned.
|
ClassGraph |
ignoreFieldVisibility()
Causes field visibility to be ignored, enabling private, package-private and protected fields to be scanned.
|
ClassGraph |
ignoreMethodVisibility()
Causes method visibility to be ignored, enabling private, package-private and protected methods to be
scanned.
|
ClassGraph |
ignoreParentClassLoaders()
Ignore parent classloaders (i.e.
|
ClassGraph |
ignoreParentModuleLayers()
Ignore parent module layers (i.e.
|
ClassGraph |
initializeLoadedClasses()
Causes classes loaded using
ClassInfo.loadClass() to be are initialized after class loading (the
default is to not initialize classes). |
ClassGraph |
overrideClassLoaders(ClassLoader... overrideClassLoaders)
Completely override (and ignore) system ClassLoaders and the java.class.path system property.
|
ClassGraph |
overrideClasspath(Iterable<?> overrideClasspathElements)
Override the automatically-detected classpath with a custom path.
|
ClassGraph |
overrideClasspath(Object... overrideClasspathElements)
Override the automatically-detected classpath with a custom path.
|
ClassGraph |
overrideClasspath(String overrideClasspath)
Override the automatically-detected classpath with a custom path, with path elements separated by
File.pathSeparatorChar.
|
ClassGraph |
overrideModuleLayers(Object... overrideModuleLayers)
Completely override (and ignore) the visible ModuleLayers, and instead scan the requested ModuleLayers.
|
ClassGraph |
rejectClasses(String... classNames)
Specifically reject one or more specific classes, preventing them from being scanned even if they are in a
accepted package.
|
ClassGraph |
rejectClasspathElementsContainingResourcePath(String... resourcePaths)
Reject classpath elements based on resource paths.
|
ClassGraph |
rejectJars(String... jarLeafNames)
Reject one or more jars, preventing them from being scanned.
|
ClassGraph |
rejectLibOrExtJars(String... jarLeafNames)
Reject one or more jars in a JRE/JDK "lib/" or "ext/" directory, preventing them from being scanned.
|
ClassGraph |
rejectModules(String... moduleNames)
Reject one or more modules, preventing them from being scanned.
|
ClassGraph |
rejectPackages(String... packageNames)
Prevent the scanning of one or more specific packages and their sub-packages.
|
ClassGraph |
rejectPaths(String... paths)
Prevent the scanning of one or more specific paths and their sub-directories / nested paths.
|
ClassGraph |
removeTemporaryFilesAfterScan()
Remove temporary files, including nested jarfiles (jarfiles within jarfiles, which have to be extracted
during scanning in order to be read) from their temporary directory as soon as the scan has completed.
|
ScanResult |
scan()
Scans the classpath, blocking until the scan is complete.
|
ScanResult |
scan(ExecutorService executorService,
int numParallelTasks)
Scans the classpath using the requested
ExecutorService and the requested degree of parallelism,
blocking until the scan is complete. |
ScanResult |
scan(int numThreads)
Scans the classpath with the requested number of threads, blocking until the scan is complete.
|
Future<ScanResult> |
scanAsync(ExecutorService executorService,
int numParallelTasks)
Asynchronously scans the classpath for matching files, returning a
Future<ScanResult> . |
void |
scanAsync(ExecutorService executorService,
int numParallelTasks,
ClassGraph.ScanResultProcessor scanResultProcessor,
ClassGraph.FailureHandler failureHandler)
Asynchronously scans the classpath, calling a
ClassGraph.ScanResultProcessor callback on success or a
ClassGraph.FailureHandler callback on failure. |
ClassGraph |
setMaxBufferedJarRAMSize(int maxBufferedJarRAMSize)
The maximum size of an inner (nested) jar that has been deflated (i.e.
|
ClassGraph |
verbose()
Switches on verbose logging to System.err.
|
ClassGraph |
verbose(boolean verbose)
Switches on verbose logging to System.err if verbose is true.
|
ClassGraph |
whitelistClasses(String... classNames)
Deprecated.
Use
acceptClasses(String...) instead. |
ClassGraph |
whitelistClasspathElementsContainingResourcePath(String... resourcePaths)
Deprecated.
|
ClassGraph |
whitelistJars(String... jarLeafNames)
Deprecated.
Use
acceptJars(String...) instead. |
ClassGraph |
whitelistLibOrExtJars(String... jarLeafNames)
Deprecated.
Use
acceptLibOrExtJars(String...) instead. |
ClassGraph |
whitelistModules(String... moduleNames)
Deprecated.
Use
acceptModules(String...) instead. |
ClassGraph |
whitelistPackages(String... packageNames)
Deprecated.
Use
acceptPackages(String...) instead. |
ClassGraph |
whitelistPackagesNonRecursive(String... packageNames)
Deprecated.
Use
acceptPackagesNonRecursive(String...) instead. |
ClassGraph |
whitelistPaths(String... paths)
Deprecated.
Use
acceptPaths(String...) instead. |
ClassGraph |
whitelistPathsNonRecursive(String... paths)
Deprecated.
Use
acceptPathsNonRecursive(String...) instead. |
public static String getVersion()
public ClassGraph verbose()
public ClassGraph verbose(boolean verbose)
verbose
- if true, enable verbose logging.public ClassGraph enableAllInfo()
Calls enableClassInfo()
, enableFieldInfo()
, enableMethodInfo()
,
enableAnnotationInfo()
, enableStaticFinalFieldConstantInitializerValues()
,
ignoreClassVisibility()
, ignoreFieldVisibility()
, and ignoreMethodVisibility()
.
public ClassGraph enableClassInfo()
ClassInfo
objects in the ScanResult
.public ClassGraph ignoreClassVisibility()
enableClassInfo()
.)public ClassGraph enableMethodInfo()
ClassInfo.getMethodInfo()
etc. By default, method info is not scanned. (Automatically calls
enableClassInfo()
.)public ClassGraph ignoreMethodVisibility()
enableClassInfo()
and
enableMethodInfo()
.)public ClassGraph enableFieldInfo()
ClassInfo.getFieldInfo()
. By default, field info is not scanned. (Automatically calls
enableClassInfo()
.)public ClassGraph ignoreFieldVisibility()
enableClassInfo()
and
enableFieldInfo()
.)public ClassGraph enableStaticFinalFieldConstantInitializerValues()
FieldInfo.getConstantInitializerValue()
.
Note that constant initializer values are usually only of primitive type, or String constants (or values that can be computed and reduced to one of those types at compiletime).
Also note that it is up to the compiler as to whether or not a constant-valued field is assigned as a constant in the field definition itself, or whether it is assigned manually in static class initializer blocks -- so your mileage may vary in being able to extract constant initializer values.
In fact in Kotlin, even constant initializers for non-static / non-final fields are stored in a field attribute in the classfile (and so these values may be picked up by ClassGraph by calling this method), although any field initializers for non-static fields are supposed to be ignored by the JVM according to the classfile spec, so the Kotlin compiler may change in future to stop generating these values, and you probably shouldn't rely on being able to get the initializers for non-static fields in Kotlin. (As far as non-final fields, javac simply does not add constant initializer values to the field attributes list for non-final fields, even if they are static, but the spec doesn't say whether or not the JVM should ignore constant initializers for non-final fields.)
Automatically calls enableClassInfo()
and enableFieldInfo()
.
public ClassGraph enableAnnotationInfo()
ClassInfo.getAnnotationInfo()
,
FieldInfo.getAnnotationInfo()
, and MethodParameterInfo.getAnnotationInfo()
. By default,
annotation info is not scanned. (Automatically calls enableClassInfo()
.)public ClassGraph enableInterClassDependencies()
ClassInfo.getClassDependencies()
, ScanResult.getClassDependencyMap()
or
ScanResult.getReverseClassDependencyMap()
. (Automatically calls enableClassInfo()
,
enableFieldInfo()
, enableMethodInfo()
, enableAnnotationInfo()
,
ignoreClassVisibility()
, ignoreFieldVisibility()
and ignoreMethodVisibility()
.)public ClassGraph disableRuntimeInvisibleAnnotations()
enableClassInfo()
.)public ClassGraph disableJarScanning()
public ClassGraph disableNestedJarScanning()
public ClassGraph disableDirScanning()
public ClassGraph disableModuleScanning()
public ClassGraph enableExternalClasses()
enableClassInfo()
.)public ClassGraph initializeLoadedClasses()
ClassInfo.loadClass()
to be are initialized after class loading (the
default is to not initialize classes).public ClassGraph removeTemporaryFilesAfterScan()
ScanResult
finalizer, or on JVM exit.public ClassGraph overrideClasspath(String overrideClasspath)
If this method is called, nothing but the provided classpath will be scanned, i.e. this causes ClassLoaders to be ignored, as well as the java.class.path system property.
overrideClasspath
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph overrideClasspath(Iterable<?> overrideClasspathElements)
Works for Iterables of any type whose toString() method resolves to a classpath element string, e.g. String, File or Path.
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph overrideClasspath(Object... overrideClasspathElements)
Works for arrays of any member type whose toString() method resolves to a classpath element string, e.g. String, File or Path.
overrideClasspathElements
- The custom classpath to use for scanning, with path elements separated by File.pathSeparatorChar.public ClassGraph filterClasspathElements(ClassGraph.ClasspathElementFilter classpathElementFilter)
classpathElementFilter
- The filter function to use. This function should return true if the classpath element path should
be scanned, and false if not.public ClassGraph filterClasspathElementsByURL(ClassGraph.ClasspathElementURLFilter classpathElementURLFilter)
URL
passed to it is a URL you want to scan.classpathElementURLFilter
- The filter function to use. This function should return true if the classpath element URL
should be scanned, and false if not.public ClassGraph addClassLoader(ClassLoader classLoader)
This call is ignored if overrideClasspath(String)
is also called, or if this method is called before
overrideClassLoaders(ClassLoader...)
.
classLoader
- The additional ClassLoader to scan.public ClassGraph overrideClassLoaders(ClassLoader... overrideClassLoaders)
ignoreParentClassLoaders()
to extract classpath URLs from only the classloaders you specified in the
parameter to `overrideClassLoaders`, and not their parent classloaders.
This call is ignored if overrideClasspath(String)
is called.
overrideClassLoaders
- The ClassLoaders to scan instead of the automatically-detected ClassLoaders.public ClassGraph ignoreParentClassLoaders()
public ClassGraph addModuleLayer(Object moduleLayer)
This call is ignored if it is called before overrideModuleLayers(Object...)
.
moduleLayer
- The additional ModuleLayer to scan. (The parameter is of type Object
for backwards
compatibility with JDK 7 and JDK 8, but the argument should be of type ModuleLayer.)public ClassGraph overrideModuleLayers(Object... overrideModuleLayers)
This call is ignored if overrideClasspath() is called.
overrideModuleLayers
- The ModuleLayers to scan instead of the automatically-detected ModuleLayers. (The parameter is of
type Object
[] for backwards compatibility with JDK 7 and JDK 8, but the argument should be
of type ModuleLayer[].)public ClassGraph ignoreParentModuleLayers()
public ClassGraph acceptPackages(String... packageNames)
N.B. Automatically calls enableClassInfo()
-- call acceptPaths(String...)
instead if you
only need to scan resources.
packageNames
- The fully-qualified names of packages to scan (using '.' as a separator). May include a glob
wildcard ('*'
).@Deprecated public ClassGraph whitelistPackages(String... packageNames)
acceptPackages(String...)
instead.acceptPackages(String...)
instead.packageNames
- The fully-qualified names of packages to scan (using '.' as a separator). May include a glob
wildcard ('*'
).public ClassGraph acceptPaths(String... paths)
paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator). May include a glob wildcard ('*'
).@Deprecated public ClassGraph whitelistPaths(String... paths)
acceptPaths(String...)
instead.acceptPaths(String...)
instead.paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator). May include a glob wildcard ('*'
).public ClassGraph acceptPackagesNonRecursive(String... packageNames)
N.B. Automatically calls enableClassInfo()
-- call acceptPathsNonRecursive(String...)
instead if you only need to scan resources.
This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
packageNames
- The fully-qualified names of packages to scan (with '.' as a separator). May not include a glob
wildcard ('*'
).@Deprecated public ClassGraph whitelistPackagesNonRecursive(String... packageNames)
acceptPackagesNonRecursive(String...)
instead.acceptPackagesNonRecursive(String...)
instead.packageNames
- The fully-qualified names of packages to scan (with '.' as a separator). May not include a glob
wildcard ('*'
).public ClassGraph acceptPathsNonRecursive(String... paths)
This may be particularly useful for scanning the package root ("") without recursively scanning everything in the jar, dir or module.
paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator). May not include a glob wildcard ('*'
).@Deprecated public ClassGraph whitelistPathsNonRecursive(String... paths)
acceptPathsNonRecursive(String...)
instead.acceptPathsNonRecursive(String...)
instead.paths
- The paths to scan, relative to the package root of the classpath element (with '/' as a
separator). May not include a glob wildcard ('*'
).public ClassGraph rejectPackages(String... packageNames)
N.B. Automatically calls enableClassInfo()
-- call rejectPaths(String...)
instead if you
only need to scan resources.
packageNames
- The fully-qualified names of packages to reject (with '.' as a separator). May include a glob
wildcard ('*'
).@Deprecated public ClassGraph blacklistPackages(String... packageNames)
rejectPackages(String...)
instead.rejectPackages(String...)
instead.packageNames
- The fully-qualified names of packages to reject (with '.' as a separator). May include a glob
wildcard ('*'
).public ClassGraph rejectPaths(String... paths)
paths
- The paths to reject (with '/' as a separator). May include a glob wildcard ('*'
).@Deprecated public ClassGraph blacklistPaths(String... paths)
rejectPaths(String...)
instead.rejectPaths(String...)
instead.paths
- The paths to reject (with '/' as a separator). May include a glob wildcard ('*'
).public ClassGraph acceptClasses(String... classNames)
N.B. Automatically calls enableClassInfo()
.
classNames
- The fully-qualified names of classes to scan (using '.' as a separator). May not include a glob
wildcard ('*'
).@Deprecated public ClassGraph whitelistClasses(String... classNames)
acceptClasses(String...)
instead.acceptClasses(String...)
instead.classNames
- The fully-qualified names of classes to scan (using '.' as a separator). May not include a glob
wildcard ('*'
).public ClassGraph rejectClasses(String... classNames)
N.B. Automatically calls enableClassInfo()
.
classNames
- The fully-qualified names of classes to reject (using '.' as a separator). May not include a glob
wildcard ('*'
).@Deprecated public ClassGraph blacklistClasses(String... classNames)
rejectClasses(String...)
instead.rejectClasses(String...)
instead.classNames
- The fully-qualified names of classes to reject (using '.' as a separator). May not include a glob
wildcard ('*'
).public ClassGraph acceptJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the jars that should be scanned (e.g. "mylib.jar"
). May contain a
wildcard glob ("mylib-*.jar"
).@Deprecated public ClassGraph whitelistJars(String... jarLeafNames)
acceptJars(String...)
instead.acceptJars(String...)
instead.jarLeafNames
- The leafnames of the jars that should be scanned (e.g. "mylib.jar"
). May contain a
wildcard glob ("mylib-*.jar"
).public ClassGraph rejectJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the jars that should be scanned (e.g. "badlib.jar"
). May contain a
wildcard glob ("badlib-*.jar"
).@Deprecated public ClassGraph blacklistJars(String... jarLeafNames)
rejectJars(String...)
instead.rejectJars(String...)
instead.jarLeafNames
- The leafnames of the jars that should be scanned (e.g. "badlib.jar"
). May contain a
wildcard glob ("badlib-*.jar"
).public ClassGraph acceptLibOrExtJars(String... jarLeafNames)
enableSystemJarsAndModules()
is called, by association with the JRE/JDK).jarLeafNames
- The leafnames of the lib/ext jar(s) that should be scanned (e.g. "mylib.jar"
). May contain
a wildcard glob ('*'
). Note that if you call this method with no parameters, all JRE/JDK
"lib/" or "ext/" jars will be accepted.@Deprecated public ClassGraph whitelistLibOrExtJars(String... jarLeafNames)
acceptLibOrExtJars(String...)
instead.acceptLibOrExtJars(String...)
instead.jarLeafNames
- The leafnames of the lib/ext jar(s) that should be scanned (e.g. "mylib.jar"
). May contain
a wildcard glob ('*'
). Note that if you call this method with no parameters, all JRE/JDK
"lib/" or "ext/" jars will be accepted.public ClassGraph rejectLibOrExtJars(String... jarLeafNames)
jarLeafNames
- The leafnames of the lib/ext jar(s) that should not be scanned (e.g.
"jre/lib/badlib.jar"
). May contain a wildcard glob ('*'
). If you call this method
with no parameters, all JRE/JDK "lib/"
or "ext/"
jars will be rejected.@Deprecated public ClassGraph blacklistLibOrExtJars(String... jarLeafNames)
rejectLibOrExtJars(String...)
instead.rejectLibOrExtJars(String...)
instead.jarLeafNames
- The leafnames of the lib/ext jar(s) that should not be scanned (e.g.
"jre/lib/badlib.jar"
). May contain a wildcard glob ('*'
). If you call this method
with no parameters, all JRE/JDK "lib/"
or "ext/"
jars will be rejected.public ClassGraph acceptModules(String... moduleNames)
moduleNames
- The names of the modules that should be scanned. May contain a wildcard glob ('*'
).@Deprecated public ClassGraph whitelistModules(String... moduleNames)
acceptModules(String...)
instead.acceptModules(String...)
instead.moduleNames
- The names of the modules that should be scanned. May contain a wildcard glob ('*'
).public ClassGraph rejectModules(String... moduleNames)
moduleNames
- The names of the modules that should not be scanned. May contain a wildcard glob ('*'
).@Deprecated public ClassGraph blacklistModules(String... moduleNames)
rejectModules(String...)
instead.rejectModules(String...)
instead.moduleNames
- The names of the modules that should not be scanned. May contain a wildcard glob ('*'
).public ClassGraph acceptClasspathElementsContainingResourcePath(String... resourcePaths)
resourcePaths
- The resource paths, any of which must be present in a classpath element for the classpath element
to be scanned. May contain a wildcard glob ('*'
).@Deprecated public ClassGraph whitelistClasspathElementsContainingResourcePath(String... resourcePaths)
acceptClasspathElementsContainingResourcePath(String...)
instead.resourcePaths
- The resource paths, any of which must be present in a classpath element for the classpath element
to be scanned. May contain a wildcard glob ('*'
).public ClassGraph rejectClasspathElementsContainingResourcePath(String... resourcePaths)
resourcePaths
- The resource paths which cause a classpath not to be scanned if any are present in a classpath
element for the classpath element. May contain a wildcard glob ('*'
).@Deprecated public ClassGraph blacklistClasspathElementsContainingResourcePath(String... resourcePaths)
rejectClasspathElementsContainingResourcePath(String...)
instead.resourcePaths
- The resource paths which cause a classpath not to be scanned if any are present in a classpath
element for the classpath element. May contain a wildcard glob ('*'
).public ClassGraph enableRemoteJarScanning()
new ClassGraph().enableURLScheme("http").enableURLScheme("https");
Scanning from http(s) URLs is disabled by default, as this may present a security vulnerability, since
classes from downloaded jars can be subsequently loaded using ClassInfo.loadClass(java.lang.Class<T>, boolean)
.
public ClassGraph enableURLScheme(String scheme)
URL
connections with the specified URL scheme (also
works for any custom URL schemes that have been defined, as long as they have more than two characters, in
order to not conflict with Windows drive letters).scheme
- the URL scheme string, e.g. "resource" for a custom "resource:" URL scheme.public ClassGraph enableSystemJarsAndModules()
"java.*"
, "javax.*"
, "javafx.*"
,
"jdk.*"
, "oracle.*"
, "sun.*"
) -- these are not scanned by default for speed.
N.B. Automatically calls enableClassInfo()
.
public ClassGraph setMaxBufferedJarRAMSize(int maxBufferedJarRAMSize)
ByteBuffer
when it
is deflated, in order for the inner jar's entries to be read. (Note that this situation of having to deflate
a nested jar to RAM or disk in order to read it is rare, because normally adding a jarfile to another jarfile
will store the inner jar, rather than deflate it, because deflating a jarfile does not usually produce any
further compression gains. If an inner jar is stored, not deflated, then its zip entries can be read directly
using ClassGraph's own zipfile central directory parser, which can use file slicing to extract entries
directly from stored nested jars.)
This is also the maximum size of a jar downloaded from an http://
or https://
classpath
URL
to RAM. Once this many bytes have been read from the URL
's InputStream
, then the
RAM contents are spilled over to a temporary file on disk, and the rest of the content is downloaded to the
temporary file. (This is also rare, because normally there are no http://
or https://
classpath entries.)
Default: 64MB (i.e. writing to disk is avoided wherever possible). Setting a lower max RAM size value will decrease ClassGraph's memory usage if either of the above rare situations occurs.
maxBufferedJarRAMSize
- The max RAM size to use for deflated inner jars or downloaded jars. This is the limit per jar, not
for the whole classpath.public ClassGraph enableMemoryMapping()
MappedByteBuffer
rather than the FileChannel
API to open files, which may be
faster for large classpaths consisting of many large jarfiles, but uses up virtual memory space.public ClassGraph enableRealtimeLogging()
verbose()
, and then sets the logger to "realtime logging mode", where log
entries are written out immediately to stderr, rather than only after the scan has completed. Can help to
identify problems where scanning is stuck in a loop, or where one scanning step is taking much longer than it
should, etc.public void scanAsync(ExecutorService executorService, int numParallelTasks, ClassGraph.ScanResultProcessor scanResultProcessor, ClassGraph.FailureHandler failureHandler)
ClassGraph.ScanResultProcessor
callback on success or a
ClassGraph.FailureHandler
callback on failure.executorService
- A custom ExecutorService
to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.scanResultProcessor
- A ClassGraph.ScanResultProcessor
callback to run on successful scan.failureHandler
- A ClassGraph.FailureHandler
callback to run on failed scan. This is passed any Throwable
thrown during the scan.public Future<ScanResult> scanAsync(ExecutorService executorService, int numParallelTasks)
Future<ScanResult>
. You should
assign the wrapped ScanResult
in a try-with-resources statement, or manually close it when you are
finished with it.executorService
- A custom ExecutorService
to use for scheduling worker tasks.numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.Future<ScanResult>
, that when resolved using get() yields a new ScanResult
object
representing the result of the scan.public ScanResult scan(ExecutorService executorService, int numParallelTasks)
ExecutorService
and the requested degree of parallelism,
blocking until the scan is complete. You should assign the returned ScanResult
in a
try-with-resources statement, or manually close it when you are finished with it.executorService
- A custom ExecutorService
to use for scheduling worker tasks. This ExecutorService
should start tasks in FIFO order to avoid a deadlock during scan, i.e. be sure to construct the
ExecutorService
with a LinkedBlockingQueue
as its task queue. (This is the default
for Executors.newFixedThreadPool(int)
.)numParallelTasks
- The number of parallel tasks to break the work into during the most CPU-intensive stage of
classpath scanning. Ideally the ExecutorService will have at least this many threads available.ScanResult
object representing the result of the scan.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public ScanResult scan(int numThreads)
ScanResult
in a try-with-resources statement, or manually close it when you are
finished with it.numThreads
- The number of worker threads to start up.ScanResult
object representing the result of the scan.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public ScanResult scan()
ScanResult
in a try-with-resources statement, or manually close it when you are finished with it.ScanResult
object representing the result of the scan.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public List<File> getClasspathFiles()
List<File>
consisting of the unique directories and jarfiles on the classpath, in classpath
resolution order.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public String getClasspath()
getClasspathURIs()
to get the full URIs for classpath elements and modules.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public List<URI> getClasspathURIs()
URI
objects representing directory/jar classpath elements and
modules. Classpath elements representing jarfiles or directories that do not exist are not included in the
returned list.URI
objects.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public List<URL> getClasspathURLs()
URL
objects representing directory/jar classpath elements and
modules. Classpath elements representing jarfiles or directories that do not exist, as well as modules with
unknown (null) location or with jrt:
location URI scheme, are not included in the returned list.URL
objects.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public List<ModuleRef> getModules()
ModuleRef
references for all the visible modules.ModuleRef
references for all the visible modules.ClassGraphException
- if any of the worker threads throws an uncaught exception, or the scan was interrupted.public ModulePathInfo getModulePathInfo()
--module-path
, --add-modules
,
--patch-module
, --add-exports
, --add-opens
, and --add-reads
.
Note that the returned ModulePathInfo
object does not include classpath entries from the traditional
classpath or system modules. Use getModules()
to get all visible modules, including anonymous,
automatic and system modules.
Also, ModulePathInfo.addExports
and ModulePathInfo.addOpens
will not contain
Add-Exports
or Add-Opens
entries from jarfile manifest files encountered during scanning,
unless you obtain the ModulePathInfo
by calling ScanResult.getModulePathInfo()
rather than by
calling getModulePathInfo()
before scan()
.
ModulePathInfo
.Copyright © 2021. All rights reserved.