Spring Boot 2 - Change Jar Name
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Changing the output jar name in a Spring Boot 2 project is usually a build-tool configuration task, not a Spring runtime setting. The exact change depends on whether the project uses Maven or Gradle, and whether you want to rename the plain jar, the executable Boot jar, or both. The safest approach is to configure the build explicitly so your CI, deployment scripts, and artifact repository all see the expected filename.
Maven: Use finalName
In Maven-based Spring Boot projects, the standard way to change the resulting jar name is build.finalName.
With that configuration, a package build produces target/my-app.jar.
This is the normal answer when someone asks how to rename the jar in a Spring Boot Maven project.
Gradle: Configure bootJar
In Gradle, you usually configure the bootJar task because that is the executable artifact produced by Spring Boot.
If you run:
the artifact will be written with the configured filename under build/libs.
Naming Versus Coordinates
Renaming the jar file does not change the Maven coordinates or the logical project identity. Those still come from values such as groupId, artifactId, and version.
That distinction matters because:
- repository publishing may still use project coordinates
- deployment scripts may reference the physical file name
- generated metadata may differ from the local jar name
If your build and deployment pipeline assumes a name derived from artifactId and version, changing only the local filename may not be enough.
Plain Jar Versus Boot Jar
Spring Boot can produce more than one jar depending on build configuration. In Gradle, for example, jar and bootJar are different tasks.
If you only rename jar but your deployment uses bootJar, the executable artifact name will not change. This is a frequent source of confusion.
Include Version or Exclude It
Whether to include the version in the filename depends on deployment style.
For immutable release artifacts, versioned names are useful:
For server environments that always want a stable name like app.jar, a fixed name may be more convenient:
Be deliberate here. A stable filename simplifies service scripts, but versioned filenames make rollback and artifact auditing easier.
Multi-Module Builds
In a multi-module build, jar naming becomes more important because multiple services may be packaged in the same CI job. If every module ends up producing a generic app.jar, downstream artifact handling gets messy quickly.
A better pattern is to derive names from the module or service identity and let versioning remain visible where appropriate.
Validate the Output Path
After changing the name, verify what your build actually produced.
For Maven:
For Gradle:
This sounds trivial, but it catches mistakes such as editing the wrong build file or configuring the wrong task.
Deployment and CI Implications
Changing the jar name can break scripts that copy or run the artifact directly.
Common places to check:
- Dockerfiles using
COPY build/libs/*.jar app.jar - systemd unit files or shell scripts that run
java -jar - CI pipelines that upload a hard-coded filename
Renaming the artifact is easy. Updating the surrounding automation is what usually gets missed.
Common Pitfalls
The most common issue is changing the wrong build setting, such as editing jar while the deployable file is produced by bootJar. Another is assuming that renaming the local file also changes Maven coordinates or published artifact metadata. Teams also often overlook CI scripts, Dockerfiles, and deployment manifests that still reference the old filename. In Maven projects, forgetting finalName and trying to solve the problem inside application properties is another dead end.
Summary
- In Maven, change the Spring Boot jar name with
build.finalName. - In Gradle, configure the
bootJartask for the executable artifact. - Know whether your pipeline uses the plain jar or the Boot jar.
- Renaming the file does not change project coordinates.
- After the change, verify build output and update deployment automation that references the old name.
Related reading
- Spring Boot 2 - Unsatisfied dependency on Feign client when autowired for service
- Spring boot 2 Converting Duration java 8 application.properties
- Spring Boot 2 health actuator default mapping
- Spring Boot 3.0.0, SQS java.lang.ClassNotFoundException org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver
- Spring boot 3 - Jakarta and Javax
- Spring Boot 3 springdoc-openapi-ui doesn't work
- Spring Boot 3.x upgrade. Could not resolve org.springframework.bootspring-boot-gradle-plugin3.0.1
- Spring boot 404 error custom error response ReST

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.