Skip to content

io microsphere classloading ArtifactDetector

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

ArtifactDetector

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

Source: microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java

Overview

The ArtifactDetector class is responsible for detecting and resolving artifacts from the classpath. It uses a list of registered ArtifactResourceResolver implementations to resolve each URL in the classpath into an appropriate Artifact instance.

ArtifactDetector supports filtering out JDK internal libraries based on the configuration flag provided during detection. It also allows customization through different ArtifactResourceResolver implementations that can be loaded via service loading mechanism.

Example Usage

`// Create an instance using the default ClassLoader
ArtifactDetector detector = new ArtifactDetector();

// Detect all artifacts including JDK libraries
List artifactsIncludingJDK = detector.detect(true);

// Detect artifacts excluding JDK libraries
List artifactsExcludingJDK = detector.detect(false);
`

You can also provide a custom ArtifactResourceResolver implementation like below:

`public class CustomArtifactResolver implements ArtifactResourceResolver {
    public Artifact resolve(URL resourceURL) {
        if (resourceURL.getProtocol().equals("file")) {
            return new FileArtifact(resourceURL); // hypothetical custom artifact
        `
        return null;
    }

    public int getPriority() {
        return Prioritized.MAX_PRIORITY; // highest priority
    }
}
}

Once registered via service loader or manually added, it will be used by the detector accordingly.

Declaration

public class ArtifactDetector

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

// Create an instance using the default ClassLoader
ArtifactDetector detector = new ArtifactDetector();

// Detect all artifacts including JDK libraries
List<Artifact> artifactsIncludingJDK = detector.detect(true);

// Detect artifacts excluding JDK libraries
List<Artifact> artifactsExcludingJDK = detector.detect(false);

Example 2

public class CustomArtifactResolver implements ArtifactResourceResolver {
    public Artifact resolve(URL resourceURL) {
        if (resourceURL.getProtocol().equals("file")) {
            return new FileArtifact(resourceURL); // hypothetical custom artifact
        }
        return null;
    }

    public int getPriority() {
        return Prioritized.MAX_PRIORITY; // highest priority
    }
}

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.classloading.ArtifactDetector;

API Reference

Public Methods

Method Description
detect
detect

See Also

  • Artifact
  • ArtifactResourceResolver
  • Prioritized

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