Skip to content

io microsphere io scanner SimpleClassScanner

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

SimpleClassScanner

Type: Class | Module: microsphere-java-core | Package: io.microsphere.io.scanner | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/io/scanner/SimpleClassScanner.java

Overview

A simple scanner for scanning Class objects under a specified package or archive.

This class provides various methods to scan and retrieve classes either by package name, resource URL, or archive file. It supports filtering based on classloader, package recursion, and custom predicates.

Example Usage

Scan all classes in a package without loading them:

`SimpleClassScanner scanner = new SimpleClassScanner();
Set> classes = scanner.scan(classLoader, "com.example.package");
`

Scan and load all classes recursively in a package:

`Set> loadedClasses = scanner.scan(classLoader, "com.example.package", true, true);
`

Scan classes from an archive file with filters:

`File archiveFile = new File("path/to/archive.jar");
Predicate> myFilter = cls -> cls.isAnnotationPresent(MyAnnotation.class);
Set> filteredClasses = scanner.scan(classLoader, archiveFile, false, myFilter);
`

Declaration

public class SimpleClassScanner

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Example 1

SimpleClassScanner scanner = new SimpleClassScanner();
Set<Class<?>> classes = scanner.scan(classLoader, "com.example.package");

Example 2

Set<Class<?>> loadedClasses = scanner.scan(classLoader, "com.example.package", true, true);

Example 3

File archiveFile = new File("path/to/archive.jar");
Predicate<Class<?>> myFilter = cls -> cls.isAnnotationPresent(MyAnnotation.class);
Set<Class<?>> filteredClasses = scanner.scan(classLoader, archiveFile, false, myFilter);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.io.scanner.SimpleClassScanner;

API Reference

Public Methods

Method Description
scan Singleton
scan It's equal to invoke #scan(ClassLoader, String, boolean, boolean) method with
scan scan Class set under specified package name or its' sub-packages in ClassLoader, if
scan
scan

Method Details

scan

public Set<Class<?>> scan(ClassLoader classLoader, String packageName)

Singleton / public final static SimpleClassScanner INSTANCE = new SimpleClassScanner();

public SimpleClassScanner() { }

/** It's equal to invoke #scan(ClassLoader, String, boolean, boolean) method with requiredLoad=false and recursive=false

scan

public Set<Class<?>> scan(ClassLoader classLoader, String packageName, boolean recursive)

It's equal to invoke #scan(ClassLoader, String, boolean, boolean) method with requiredLoad=false

scan

public Set<Class<?>> scan(ClassLoader classLoader, String packageName, final boolean recursive, boolean requiredLoad)

scan Class set under specified package name or its' sub-packages in ClassLoader, if requiredLoad indicates true , try to load those classes.

See Also

  • SimpleClassScanner

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally