Packaging and Running Spring Boot Applications
Packaging and Running Spring Boot Applications
When development is done, you still need to ship the app. Spring Boot packages everything into a runnable artifact, and the deploy story is refreshingly simple. The default Maven package goal produces an executable fat jar containing your code, all dependencies, and the embedded server.
Building the jar
Run mvn package or ./gradlew bootJar and the build produces a jar under the target or build directory. The Spring Boot Maven plugin makes the jar executable by adding a special loader. You can now run it anywhere a JVM exists.
java -jar target/demo-app-0.0.1-SNAPSHOT.jar
WAR deployment
If you must deploy to an external servlet container, mark the Tomcat starter dependency with provided scope so the container supplies its own server, and extend SpringBootServletInitializer in your main class. The resulting WAR deploys like any other web application.
From jar to container
A small Dockerfile is the modern packaging step:
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY target/demo.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
Running with configuration
Pass configuration at runtime with arguments (like --server.port=9090), environment variables, or a profile toggle (--spring.profiles.active=prod). Because configuration is externalized, the same artifact runs in every environment without rebuilding.
Health checks
Add spring-boot-starter-actuator and the /actuator/health endpoint gives orchestrators and load balancers a live health probe. Combined with readiness and liveness groups, it makes the jar deployment-friendly in modern platforms.
Key Points
mvn packagecreates an executable fat jar with the embedded server.- Run it anywhere with
java -jar. - Use WAR packaging only when an external container is required.
- Externalize configuration so one artifact runs in all environments.
- Expose health endpoints via Spring Boot Actuator.