Maven finalName: control the jar file name (default artifactId-version)
Codemia Knowledge Hub ·
Set <finalName> inside the <build> section of pom.xml. Without it, Maven names the packaged output (JAR, WAR and so on) artifactId-version, followed by the packaging extension. The final name is the file name of the packaged output once the build completes, so it is what you see when you deploy or distribute the project.
The default name
Maven's default pattern is:
With artifactId my-app and version 1.0.0, the build produces my-app-1.0.0.jar.
Setting <finalName>
Whatever the artifactId and version, the JAR is now named my-custom-name.jar. The value can be a fixed string, as here, or built from project properties, as in the examples below.
Reasons to do this include:
- Naming conventions: Some deployment systems or teams require specific file names.
- Dropping the version: Simpler file names when the version is already part of the directory structure.
- Environment-specific names: Telling test and production builds apart.
- Fitting other tools: Larger build systems or release processes may expect a particular name.
Different names per environment with profiles
Profiles let each environment set its own final name:
Running mvn clean package -P production produces my-app-prod.jar.
Leaving the version out
To build a JAR without the version number:
This produces my-app.jar.
What else a custom name affects
- CI/CD pipelines: Update any pipeline steps that look for the file by name.
- Descriptor files: If
.yaml,.xmlor.jsonfiles in the project reference the artifact by name, update them too. - Artifact repositories:
finalNamechanges the file built intarget/. When you runmvn installormvn deploy, the copy stored in the repository (Nexus, Artifactory, or your local repository) is still named after theartifactIdandversion.
| Feature | Default Behavior | Customized Behavior |
| Naming | artifactId-version.jar | Custom name defined in <finalName> |
| Profiles | Not environment-specific | Supports environment-specific configurations |
| Version | Included by default | Can be excluded or modified |
Related reading
- Conversion from ListT to array T
- Convert a byte array to integer in Java and vice versa
- Convert a JSON String to a HashMap
- Convert a string representation of a hex dump to a byte array using Java?
- Convert any object to a byte
- Convert array of strings into a string in Java
- Convert ArrayList<String> to String[] array
- Convert boolean to int in Java
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.