Controlling Maven final name of jar artifact
For Maven >= 3
<packaging>jar</packaging> <build> <finalName>WhatEverYouLikey</finalName> </build>
(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.StringRequired: NoUser Property: jar.finalNameDefault: ${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] ------------------------------------------------------------------------