Home >Java >javaTutorial >How do I control the final name of a Maven JAR artifact?
Understanding the 'finalName' Property
The 'finalName' property in a Maven pom.xml can be used to control the destination and naming of the generated JAR artifact. However, the provided example demonstrates a misunderstanding about how this property works.
Setting 'finalName' for Modern Maven Versions
In Maven versions 3 and above, the 'finalName' property can be directly set in the packaging configuration section of the pom.xml:
<packaging>jar</packaging> <build> <finalName>WhatEverYouLikey</finalName> </build>
Setting 'finalName' for Older Maven Versions
For older Maven versions, the 'finalName' property must be set in the configuration of 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>
Troubleshooting
In the provided example, the 'finalName' property is not properly set in the plugin configuration, resulting in the default artifact name. To fix this, the maven-jar-plugin configuration should be added to the pom.xml, specifying the 'finalName' as desired.
The above is the detailed content of How do I control the final name of a Maven JAR artifact?. For more information, please follow other related articles on the PHP Chinese website!