Home > Java > javaTutorial > How to Control the Final Name of a Maven JAR Artifact?

How to Control the Final Name of a Maven JAR Artifact?

Mary-Kate Olsen
Release: 2024-11-09 19:02:02
Original
698 people have browsed it

How to Control the Final Name of a Maven JAR Artifact?

Controlling the Final Name of a Maven JAR Artifact

Understanding the Project Build Final Name

The project.build.finalName property is intended to define the final name of the artifact generated by Maven. However, in certain scenarios, it may not operate as expected. To control this aspect accurately, two approaches are available, one for newer Maven versions and another for older ones.

Maven 3 and Higher

For Maven 3 and subsequent versions, including the current one, the direct manipulation of the finalName property in the section of the POM is sufficient. As demonstrated below:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    <packaging>jar</packaging>
    <build>
        <finalName>WhateverYouLike</finalName>
    </build>
    ...
</project>
Copy after login

Older Maven Versions

For older versions of Maven, setting the finalName property in the section might not suffice. Instead, it needs to be configured within the Maven JAR plugin as follows:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <finalName>myJar</finalName>
        </configuration>
    </plugin>
Copy after login

This approach ensures the desired final artifact name.

The above is the detailed content of How to Control the Final Name of a Maven JAR Artifact?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template