Class ClassPathScanner
java.lang.Object
tk.airshipcraft.commonlib.utils.classes.ClassPathScanner
A utility class for scanning the classpath to find classes of a particular type.
It can scan within specified packages or across the entire classpath.
This can be particularly useful for dynamically loading classes at runtime
for purposes such as plugin systems or application frameworks.
- Since:
- 2023-05-31
- Version:
- 1.0.0
- Author:
- Locutusque, notzune
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ClassPathScanner
(String... packages) Constructor with package names to restrict the scanning scope. -
Method Summary
Modifier and TypeMethodDescriptionScans for all .class files available in the classpath of the current thread's context class loader.scanClasses
(Class<?> superClass, String... packages) Scans for all classes extending the specified superclass within the given package names.scanClasses
(Class<T> superClass, List<String> packages) Scans for all classes extending the specified superclass within the given package names.
-
Constructor Details
-
ClassPathScanner
public ClassPathScanner()Default constructor. -
ClassPathScanner
Constructor with package names to restrict the scanning scope.- Parameters:
packages
- Array of package names to scan within.
-
-
Method Details
-
scanClasses
Scans for all classes extending the specified superclass within the given package names.- Parameters:
superClass
- The class to scan for subclasses.packages
- A list of package names to restrict the scanning scope.- Returns:
- A list of classes that extend the specified superclass.
-
scanClasses
Scans for all classes extending the specified superclass within the given package names.- Type Parameters:
T
- The type parameter representing the superclass.- Parameters:
superClass
- The class to scan for subclasses.packages
- A list of package names to restrict the scanning scope.- Returns:
- A list of classes that extend the specified superclass.
-
scanClasses
Scans for all .class files available in the classpath of the current thread's context class loader. It is assumed that this method will be used in an environment where the classes are unpacked or directly available as .class files (not within a JAR).- Returns:
- A list of
Class<?>
objects representing all the classes found in the classpath.
-