@Beta public final class ClassPath extends Object
ClassLoader
and finds all loadable classes and resources.
Warning: Current limitations:
URLClassLoader
instances or
the system class loader.
file:
URLs.
In 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 |
---|---|
static class |
ClassPath.ClassInfo
Represents a class that can be loaded through
ClassPath.ClassInfo.load() . |
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 | Method and Description |
---|---|
static ClassPath |
from(ClassLoader classloader)
Returns a
ClassPath representing all classes and resources loadable from classloader and its ancestor class loaders. |
ImmutableSet<ClassPath.ClassInfo> |
getAllClasses()
Returns all classes loadable from the current class path.
|
ImmutableSet<ClassPath.ResourceInfo> |
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.
|
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClasses()
Returns all top level classes loadable from the current class path.
|
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClasses(String packageName)
Returns all top level classes whose package name is
packageName . |
ImmutableSet<ClassPath.ClassInfo> |
getTopLevelClassesRecursive(String packageName)
Returns all top level classes whose package name is
packageName or starts with packageName followed by a '.'. |
public static ClassPath from(ClassLoader classloader) throws IOException
ClassPath
representing all classes and resources loadable from classloader
and its ancestor class loaders.
Warning: ClassPath
can find classes and resources only from:
URLClassLoader
instances' file:
URLs
URLClassLoader
(as in Java 9), ClassPath
searches the files from the java.class.path
system property.
IOException
- if the attempt to read class path resources (jar files or directories)
failed.public ImmutableSet<ClassPath.ResourceInfo> getResources()
public ImmutableSet<ClassPath.ClassInfo> getAllClasses()
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses()
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses(String packageName)
packageName
.public ImmutableSet<ClassPath.ClassInfo> getTopLevelClassesRecursive(String packageName)
packageName
or starts with packageName
followed by a '.'.Copyright © 2010–2018. All rights reserved.