Skip to content

io microsphere classloading MavenArtifactResourceResolver

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

MavenArtifactResourceResolver

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

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

Overview

A resolver implementation for Maven artifact metadata, extracting information from Maven POM properties files.

This class extends the StreamArtifactResourceResolver, which provides a base for resolving artifacts by reading metadata from streams (either from archives or directly from resources). This resolver specifically targets Maven-style artifacts where metadata is stored in "pom.properties" files under the "META-INF/maven/" directory.

How It Works

- The resolver checks if a given resource path matches the pattern of a Maven POM properties file using the
`#isArtifactMetadata(String)` method. The pattern is typically:
`META-INF/maven///pom.properties`.
- If a match is found, it reads the properties file via the
`#resolve(URL, InputStream, ClassLoader)` method and extracts key metadata: groupId, artifactId, and version.
- It then constructs an `Artifact` object using these properties and associates it with the original URL.

Example Usage

`// Create a resolver with default priority
MavenArtifactResourceResolver resolver = new MavenArtifactResourceResolver();

// Resolve artifact metadata from a JAR that contains META-INF/maven/org.example/my-artifact/pom.properties
URL resourceURL = new URL("jar:file:/path/to/your-artifact.jar!/some/path");
Artifact artifact = resolver.resolve(resourceURL);

if (artifact != null) {
    System.out.println("Resolved Artifact:");
    System.out.println("Group ID: " + artifact.getGroupId());
    System.out.println("Artifact ID: " + artifact.getArtifactId());
    System.out.println("Version: " + artifact.getVersion());
`
}

Customization

You may extend this class to customize how artifact metadata is resolved or how the resulting artifact object is constructed. For example, you could override the following methods:

- `#isArtifactMetadata(String)` – to support custom metadata paths.
- `#resolveArtifactMetaInfoInMavenPomProperties(Properties, URL)` – to add additional logic when parsing the
POM properties or to enrich the resulting artifact.

Declaration

public class MavenArtifactResourceResolver extends StreamArtifactResourceResolver

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

// Create a resolver with default priority
MavenArtifactResourceResolver resolver = new MavenArtifactResourceResolver();

// Resolve artifact metadata from a JAR that contains META-INF/maven/org.example/my-artifact/pom.properties
URL resourceURL = new URL("jar:file:/path/to/your-artifact.jar!/some/path");
Artifact artifact = resolver.resolve(resourceURL);

if (artifact != null) {
    System.out.println("Resolved Artifact:");
    System.out.println("Group ID: " + artifact.getGroupId());
    System.out.println("Artifact ID: " + artifact.getArtifactId());
    System.out.println("Version: " + artifact.getVersion());
}

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.MavenArtifactResourceResolver;

See Also

  • Artifact
  • StreamArtifactResourceResolver

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