Package com.google.common.reflect
Class ClassPath
- java.lang.Object
-
- com.google.common.reflect.ClassPath
-
@Beta public final class ClassPath extends Object
Scans the source of aClassLoader
and finds all loadable classes and resources.Warning: Current limitations:
- Looks only for files and JARs in URLs available from
URLClassLoader
instances or the system class loader. - Only understands
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.
- Since:
- 14.0
- Author:
- Ben Yu
- Looks only for files and JARs in URLs available from
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassPath.ClassInfo
Represents a class that can be loaded throughClassPath.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClassPath
from(ClassLoader classloader)
Returns aClassPath
representing all classes and resources loadable fromclassloader
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 ispackageName
.ImmutableSet<ClassPath.ClassInfo>
getTopLevelClassesRecursive(String packageName)
Returns all top level classes whose package name ispackageName
or starts withpackageName
followed by a '.'.
-
-
-
Method Detail
-
from
public static ClassPath from(ClassLoader classloader) throws IOException
Returns aClassPath
representing all classes and resources loadable fromclassloader
and its ancestor class loaders.Warning:
ClassPath
can find classes and resources only from:URLClassLoader
instances'file:
URLs- the system class loader. To search the
system class loader even when it is not a
URLClassLoader
(as in Java 9),ClassPath
searches the files from thejava.class.path
system property.
- Throws:
IOException
- if the attempt to read class path resources (jar files or directories) failed.
-
getResources
public 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.
-
getAllClasses
public ImmutableSet<ClassPath.ClassInfo> getAllClasses()
Returns all classes loadable from the current class path.- Since:
- 16.0
-
getTopLevelClasses
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses()
Returns all top level classes loadable from the current class path.
-
getTopLevelClasses
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClasses(String packageName)
Returns all top level classes whose package name ispackageName
.
-
getTopLevelClassesRecursive
public ImmutableSet<ClassPath.ClassInfo> getTopLevelClassesRecursive(String packageName)
Returns all top level classes whose package name ispackageName
or starts withpackageName
followed by a '.'.
-
-