What Is an Apache Maven Artifact

Last Updated : 23 Apr, 2026

An Apache Maven artifact is a file (usually a JAR) created during the build process. It represents a reusable unit like a library or module. Artifacts are stored in repositories to manage dependencies.

  • groupId: This is the unique identifier of the organization or group that created the project.
  • artifactId: This is the unique name of the project.
  • version: This indicates the specific version of the artifact.

Steps to Setting Up a Maven Project

Follow the steps below to Setting Up a Maven Project

Step 1: Create a New Maven Project

Create a new Maven project using the below Maven command.

mvn archetype:generate -DgroupId=com.example.myapp -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Step 2: Add Dependencies

Dependencies are specified in the pom.xml file. For instance, to add the JUnit library for testing, you would add the following dependency.

Java
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    <scope>test</scope>
</dependency>

Step 3: Configuring Plugins

Plugins are added similarly to dependencies in the pom.xml file. For example, to use the Maven Compiler Plugin, you would add.

Java
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Example : pom.xml File

Here’s a complete example of a pom.xml file for a basic Maven project.

XML
<project xmlns="https://maven.apache.org/POM/4.0.0"
         xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.myapp</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Common Maven Commands

Clean Project:

This command removes all the files that are generated by the previous build.

mvn clean

Output:

[caption width="800"]

mvn clean

[/caption]

Compile Project:

Compiles the source code of the project.

mvn compile

Output:

[caption width="800"]

mvn compile

[/caption]

Test Project:

Runs the tests using a suitable testing framework.

mvn test

Output:

[caption width="800"]

mvn test

[/caption]

Package Project:

It takes the compiled code and packages it into a JAR file.

mvn package

Output:

[caption width="800"]

mvn package

[/caption]

Install Project:

Installs the package into the local repository, which can be used as a dependency in other projects locally.

mvn install

Output:

[caption width="800"]

mvn install

[/caption]

Maven Build Success:

[caption width="800"]

Build Success

[/caption]

Comment
Article Tags:

Explore