Controlling Maven final name of jar artifact
For Maven >= 3
<packaging>jar</packaging>
<build>
<finalName>WhatEverYouLikey</finalName>
</build>
See bug report/documentation.
(Credits to Matthew's and his comment)
For older Maven versions
You set the finalName
property in the plugin configuration section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>myJar</finalName>
</configuration>
</plugin>
As indicated in the official documentation.
All of the provided answers are more complicated than necessary. Assuming you are building a jar file, all you need to do is add a <jar.finalName>
tag to your <properties>
section:
<properties>
<jar.finalName>${project.name}</jar.finalName>
</properties>
This will generate a jar:
project/target/${project.name}.jar
This is in the documentation - note the User Property
:
finalName:
Name of the generated JAR.
Type: java.lang.String
Required: No
User Property: jar.finalName
Default: ${project.build.finalName}
Command Line Usage
You should also be able to use this option on the command line with:
mvn -Djar.finalName=myCustomName ...
You should get myCustomName.jar, although I haven't tested this.
@Maxim
try this...
pom.xml
<groupId>org.opensource</groupId>
<artifactId>base</artifactId>
<version>1.0.0.SNAPSHOT</version>
..............
<properties>
<my.version>4.0.8.8</my.version>
</properties>
<build>
<finalName>my-base-project</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${project.build.finalName}.${project.packaging}</file>
<generatePom>false</generatePom>
<pomFile>pom.xml</pomFile>
<version>${my.version}</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Commnad mvn clean install
Output
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ base ---
[INFO] Building jar: D:\dev\project\base\target\my-base-project.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ base ---
[INFO] Installing D:\dev\project\base\target\my-base-project.jar to H:\dev\.m2\repository\org\opensource\base\1.0.0.SNAPSHOT\base-1.0.0.SNAPSHOT.jar
[INFO] Installing D:\dev\project\base\pom.xml to H:\dev\.m2\repository\org\opensource\base\1.0.0.SNAPSHOT\base-1.0.0.SNAPSHOT.pom
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default) @ base ---
[INFO] Installing D:\dev\project\base\my-base-project.jar to H:\dev\.m2\repository\org\opensource\base\4.0.8.8\base-4.0.8.8.jar
[INFO] Installing D:\dev\project\base\pom.xml to H:\dev\.m2\repository\org\opensource\base\4.0.8.8\base-4.0.8.8.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Reference
At the package stage, the plugin allows configuration of the imported file names via file mapping:
maven-ear-plugin
http://maven.apache.org/plugins/maven-ear-plugin/examples/customize-file-name-mapping.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
[...]
<fileNameMapping>full</fileNameMapping>
</configuration>
</plugin>
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#outputFileNameMapping
If you have configured your version to be 'testing' via a profile or something, this would work for a war package:
maven-war-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<encoding>UTF-8</encoding>
<outputFileNameMapping>@{groupId}@-@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
</configuration>
</plugin>
This works for me
mvn jar:jar -Djar.finalName=custom-jar-name