Class ClassPath
java.lang.Object
cloud.opencode.base.reflect.scan.ClassPath
ClassPath Scanner
类路径扫描器
Scans the classpath for classes and resources. Similar to Guava ClassPath.
扫描类路径中的类和资源。 类似于Guava ClassPath。
Features | 主要功能:
- Classpath scanning - 类路径扫描
- Package scanning - 包扫描
- Resource discovery - 资源发现
Usage Examples | 使用示例:
ClassPath classPath = ClassPath.from(ClassLoader.getSystemClassLoader());
Set<ClassInfo> classes = classPath.getTopLevelClasses("com.example");
Set<ResourceInfo> resources = classPath.getResources();
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: No (class loader must be non-null) - 空值安全: 否(类加载器须非空)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassPathfrom(ClassLoader classLoader) Creates a ClassPath from the given ClassLoader 从给定ClassLoader创建ClassPathstatic ClassPathCreates a ClassPath from the thread context ClassLoader 从线程上下文ClassLoader创建ClassPathstatic ClassPathCreates a ClassPath from the system ClassLoader 从系统ClassLoader创建ClassPathGets all classes 获取所有类getClassesInPackage(String packageName) Gets classes in the specified package (exact match) 获取指定包中的类(精确匹配)getClassesRecursively(String packageName) Gets classes in the specified package and subpackages 获取指定包及子包中的类Gets the class loader 获取类加载器Gets all resources 获取所有资源getResourcesInPackage(String packageName) Gets resources in the specified package 获取指定包中的资源getResourcesWithExtension(String extension) Gets resources with specific extension 获取具有特定扩展名的资源getTopLevelClassesInPackage(String packageName) Gets top-level classes in the specified package 获取指定包中的顶层类getTopLevelClassesRecursively(String packageName) Gets top-level classes recursively 递归获取顶层类Streams all classes 流式获取所有类Streams all resources 流式获取所有资源toString()
-
Method Details
-
from
Creates a ClassPath from the given ClassLoader 从给定ClassLoader创建ClassPath- Parameters:
classLoader- the class loader | 类加载器- Returns:
- the ClassPath | ClassPath
-
fromSystemClassLoader
Creates a ClassPath from the system ClassLoader 从系统ClassLoader创建ClassPath- Returns:
- the ClassPath | ClassPath
-
fromContextClassLoader
Creates a ClassPath from the thread context ClassLoader 从线程上下文ClassLoader创建ClassPath- Returns:
- the ClassPath | ClassPath
-
getAllClasses
-
getResources
Gets all resources 获取所有资源- Returns:
- set of ResourceInfo | ResourceInfo集合
-
getClassesInPackage
-
getTopLevelClassesInPackage
-
getClassesRecursively
-
getTopLevelClassesRecursively
-
getResourcesInPackage
Gets resources in the specified package 获取指定包中的资源- Parameters:
packageName- the package name | 包名- Returns:
- set of ResourceInfo | ResourceInfo集合
-
getResourcesWithExtension
Gets resources with specific extension 获取具有特定扩展名的资源- Parameters:
extension- the extension (without dot) | 扩展名(不含点)- Returns:
- set of ResourceInfo | ResourceInfo集合
-
getClassLoader
-
streamClasses
-
streamResources
Streams all resources 流式获取所有资源- Returns:
- stream of ResourceInfo | ResourceInfo流
-
toString
-