ClassLoader and finds all loadable classes and resources.
ClassPathWe recommend using ClassGraph
instead of ClassPath. ClassGraph improves upon ClassPath in several ways,
including addressing many of its limitations. Limitations of ClassPath include:
URLClassLoader instances or
the system class loader. This means it does
not look for classes in the module path.
file: URLs. This means that it does not understand jrt:/ URLs, among others.
$ in its name is a nested class.
ClassPath and symlinksIn the case of directory classloaders, symlinks are supported but cycles are not traversed. This guarantees discovery of each unique loadable resource. However, not all possible aliases for resources on cyclic paths will be listed.
| Modifier and Type | Class and Description |
|---|---|
| public static class | ClassPath.ClassInfo
Represents a class that can be loaded through |
| pack-priv static class | ClassPath.LocationInfo
Represents a single location (a directory or a jar file) in the class path and is responsible for scanning resources from this location. |
| public static class | ClassPath.ResourceInfo
Represents a class path resource that can be either a class file or any other resource file loadable from the class path. |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final Splitter | CLASS_PATH_ATTRIBUTE_SEPARATOR
Separator for the Class-Path manifest attribute value in jar files. |
| private static final Logger | |
| private final ImmutableSet |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ClassPath | from(ClassLoader classloader)
Returns a |
| public ImmutableSet | |
| private static ImmutableList | |
| pack-priv static String | |
| pack-priv static ImmutableMap | |
| pack-priv static URL | getClassPathEntry(File jarFile, String path)
Returns the absolute uri of the Class-Path entry value as specified in JAR File Specification. |
| pack-priv static ImmutableSet | getClassPathFromManifest(File jarFile, Manifest manifest)
Returns the class path URIs specified by the |
| public ImmutableSet | getResources()
Returns all resources loadable from the current class path, including the class files of all loadable classes but excluding the "META-INF/MANIFEST.MF" file. |
| public ImmutableSet | |
| public ImmutableSet | getTopLevelClasses(String packageName)
Returns all top level classes whose package name is |
| public ImmutableSet | getTopLevelClassesRecursive(String packageName)
Returns all top level classes whose package name is |
| pack-priv static ImmutableSet | locationsFrom(ClassLoader classloader)
Returns all locations that |
| pack-priv static ImmutableList | parseJavaClassPath()
Returns the URLs in the class path specified by the |
| pack-priv static File |
| CLASS_FILE_NAME_EXTENSION | back to summary |
|---|---|
| private static final String CLASS_FILE_NAME_EXTENSION | |
| CLASS_PATH_ATTRIBUTE_SEPARATOR | back to summary |
|---|---|
| private static final Splitter CLASS_PATH_ATTRIBUTE_SEPARATOR Separator for the Class-Path manifest attribute value in jar files. | |
| logger | back to summary |
|---|---|
| private static final Logger logger | |
| resources | back to summary |
|---|---|
| private final ImmutableSet<ClassPath. | |
| ClassPath | back to summary |
|---|---|
| private ClassPath(ImmutableSet<ClassPath. | |
| from | back to summary |
|---|---|
| public static ClassPath from(ClassLoader classloader) throws IOException Returns a Warning:
| |
| getAllClasses | back to summary |
|---|---|
| public ImmutableSet Returns all classes loadable from the current class path.
| |
| getClassLoaderUrls | back to summary |
|---|---|
| private static ImmutableList | |
| getClassName | back to summary |
|---|---|
pack-priv static String getClassName(String filename)
| |
| getClassPathEntries | back to summary |
|---|---|
pack-priv static ImmutableMap
| |
| getClassPathEntry | back to summary |
|---|---|
| pack-priv static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException Returns the absolute uri of the Class-Path entry value as specified in JAR File Specification. Even though the specification only talks about relative urls, absolute urls are actually supported too (for example, in Maven surefire plugin).
| |
| getClassPathFromManifest | back to summary |
|---|---|
| pack-priv static ImmutableSet Returns the class path URIs specified by the
| |
| getResources | back to summary |
|---|---|
| public ImmutableSet Returns all resources loadable from the current class path, including the class files of all loadable classes but excluding the "META-INF/MANIFEST.MF" file. | |
| getTopLevelClasses | back to summary |
|---|---|
| public ImmutableSet Returns all top level classes loadable from the current class path. Note that "top-level-ness"
is determined heuristically by class name (see | |
| getTopLevelClasses | back to summary |
|---|---|
| public ImmutableSet Returns all top level classes whose package name is | |
| getTopLevelClassesRecursive | back to summary |
|---|---|
| public ImmutableSet Returns all top level classes whose package name is | |
| locationsFrom | back to summary |
|---|---|
| pack-priv static ImmutableSet Returns all locations that | |
| parseJavaClassPath | back to summary |
|---|---|
| pack-priv static ImmutableList Returns the URLs in the class path specified by the
| |
| toFile | back to summary |
|---|---|
pack-priv static File toFile(URL url)
| |
load.
| Modifier and Type | Field and Description |
|---|---|
| private final String |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public String | |
| public String | |
| public boolean | isTopLevel()
Returns true if the class name "looks to be" top level (not nested), that is, it includes no '$' in the name. |
| public Class | |
| public String | toString()
Overrides com. |
| className | back to summary |
|---|---|
| private final String className | |
| ClassInfo | back to summary |
|---|---|
| pack-priv ClassInfo(File file, String resourceName, ClassLoader loader) | |
| getName | back to summary |
|---|---|
| public String getName() Returns the fully qualified name of the class. Behaves identically to | |
| getPackageName | back to summary |
|---|---|
| public String getPackageName() Returns the package name of the class, without attempting to load the class. Behaves similarly to But note that this method may behave differently for a class in the default package: For
such classes, this method always returns an empty string. But under some version of Java,
| |
| getSimpleName | back to summary |
|---|---|
| public String getSimpleName() Returns the simple name of the underlying class as given in the source code. Behaves similarly to But note that this class uses heuristics to identify the simple name. See a related discussion in issue 3349. | |
| isTopLevel | back to summary |
|---|---|
| public boolean isTopLevel() Returns true if the class name "looks to be" top level (not nested), that is, it includes no
'$' in the name. This method may return false for a top-level class that's intentionally
named with the '$' character. If this is a concern, you could use
| |
| load | back to summary |
|---|---|
| public Class Loads (but doesn't link or initialize) the class.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides com. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private final ClassLoader | |
| pack-priv final File |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| public final File | |
| public int | |
| private void | |
| private void | |
| private void | scanDirectory(File
the root of the directory to scan directory, String resource path prefix inside packagePrefix, Set<File> classloader for any files found
under directorycanonical files already visited in the current directory tree path, for
cycle elimination currentPath, ImmutableSet.Recursively scan the given directory, adding resources for each file encountered. |
| private void | |
| private void | |
| public ImmutableSet | |
| public ImmutableSet | |
| public String |
| classloader | back to summary |
|---|---|
| private final ClassLoader classloader | |
| home | back to summary |
|---|---|
| pack-priv final File home | |
| LocationInfo | back to summary |
|---|---|
| pack-priv LocationInfo(File home, ClassLoader classloader) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| file | back to summary |
|---|---|
| public final File file() Returns the file this location is from. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| scan | back to summary |
|---|---|
| private void scan(File file, Set<File> scannedUris, ImmutableSet. | |
| scanDirectory | back to summary |
|---|---|
| private void scanDirectory(File directory, ImmutableSet. | |
| scanDirectory | back to summary |
|---|---|
| private void scanDirectory(File directory, String packagePrefix, Set<File> currentPath, ImmutableSet. Recursively scan the given directory, adding resources for each file encountered. Symlinks which have already been traversed in the current tree path will be skipped to eliminate cycles; otherwise symlinks are traversed. | |
| scanJar | back to summary |
|---|---|
| private void scanJar(File file, Set<File> scannedUris, ImmutableSet. | |
| scanJarFile | back to summary |
|---|---|
| private void scanJarFile(JarFile file, ImmutableSet. | |
| scanResources | back to summary |
|---|---|
| public ImmutableSet Scans this location and returns all scanned resources. | |
| scanResources | back to summary |
|---|---|
| public ImmutableSet Scans this location and returns all scanned resources. This file and jar files from "Class-Path" entry in the scanned manifest files will be
added to A file will be scanned at most once even if specified multiple times by one or multiple
jar files' "Class-Path" manifest entries. Particularly, if a jar file from the "Class-Path"
manifest entry is already in Note that when you call | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private final File | |
| pack-priv final ClassLoader | |
| private final String |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public final ByteSource | |
| public final CharSource | asCharSource(Charset charset)
Returns a |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| pack-priv final File | |
| public final String | |
| public int | |
| pack-priv static ClassPath. | |
| public String | |
| public final URL |
| file | back to summary |
|---|---|
| private final File file | |
| loader | back to summary |
|---|---|
| pack-priv final ClassLoader loader | |
| resourceName | back to summary |
|---|---|
| private final String resourceName | |
| ResourceInfo | back to summary |
|---|---|
| pack-priv ResourceInfo(File file, String resourceName, ClassLoader loader) | |
| asByteSource | back to summary |
|---|---|
| public final ByteSource asByteSource() Returns a
| |
| asCharSource | back to summary |
|---|---|
| public final CharSource asCharSource(Charset charset) Returns a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getFile | back to summary |
|---|---|
| pack-priv final File getFile() Returns the file that includes this resource. | |
| getResourceName | back to summary |
|---|---|
| public final String getResourceName() Returns the fully qualified name of the resource. Such as "com/mycomp/foo/bar.txt". | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| of | back to summary |
|---|---|
| pack-priv static ClassPath. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| url | back to summary |
|---|---|
| public final URL url() Returns the url identifying the resource.
| |