Java Academy

Master Java Development

Menu

Core Java

Servlets

JDBC

Microservices

Build Tools

APIs

Build Tools · Lesson 12

Publishing and Packaging Artifacts

Packaging Java Software

A build artifact is a versioned output that can be tested, deployed, or shared. Java projects commonly publish JAR libraries, executable JARs, or WAR files for servlet containers. Reproducible packaging makes releases traceable and rollback practical.

Describing an Artifact

Artifact coordinates identify a published module by group, name, and version. The Java class below models that identity and demonstrates why each part should be explicit.

public record ArtifactCoordinate(String group, String name, String version) {
    public String repositoryPath() {
        return group.replace('.', '/') + "/" + name + "/" + version;
    }

    public static void main(String[] arguments) {
        ArtifactCoordinate coordinate = new ArtifactCoordinate(
                "com.javaacademy", "lesson-service", "1.4.0");
        System.out.println(coordinate.repositoryPath());
    }
}

Artifact Types

ArtifactContainsTypical consumer
JAR libraryCompiled classes and resourcesAnother Java project
Executable JARApplication and runtime launcherContainer or VM
WARWeb application structureServlet container
Source JARSource filesDevelopers and debuggers

Common Mistake and Practices

Common Mistake: Publishing a mutable artifact under the same version repeatedly. Consumers may cache different bytes for the same coordinate, making failures difficult to reproduce.

  • Use immutable versioned artifacts.
  • Include checksums and release metadata.
  • Test the packaged output, not only classes in the build directory.
  • Publish source and documentation when useful.
  • Separate snapshot and release repositories.

Real-World Use Case

A shared Java Academy content library is published to an internal repository with a semantic version. Service builds consume that exact version and can roll back by selecting the previous artifact.

Quiz Check

Quick Knowledge Test

Loading quiz questions...