Executable Jar

Building the Jar

spring-boot-maven-plugin builds a fat jar: your classes, all dependency jars and a small launcher, in one file. Run it anywhere that has Java 17+.

Example

./mvnw clean package -DskipTests
ls -lh target/*.jar
java -jar target/shopease-1.0.0.jar --spring.profiles.active=prod

Example output

[INFO] --- spring-boot:3.3.4:repackage (repackage) @ shopease ---
[INFO] BUILD SUCCESS
-rw-r--r-- 1 dev dev 58M Mar 14 10:02 target/shopease-1.0.0.jar
INFO  c.s.ShopEaseApplication : The following 1 profile is active: "prod"
INFO  c.s.ShopEaseApplication : Started ShopEaseApplication in 3.912 seconds

Inside the Jar

shopease-1.0.0.jar
 ├── META-INF/MANIFEST.MF        Main-Class: org.springframework.boot.loader.launch.JarLauncher
 │                               Start-Class: com.shopease.ShopEaseApplication
 ├── org/springframework/boot/loader/...   (the launcher)
 └── BOOT-INF/
      ├── classes/               your code + application.yml
      ├── lib/                   spring-web-6.1.x.jar, hibernate-core-6.5.x.jar, mysql-connector-j.jar ...
      └── layers.idx             used for Docker layers

Production Settings

  • Pass secrets as environment variables: SPRING_DATASOURCE_PASSWORD, never inside the jar.
  • Set memory: java -XX:MaxRAMPercentage=75 -jar app.jar (works well in containers).
  • Graceful shutdown: server.shutdown=graceful and spring.lifecycle.timeout-per-shutdown-phase=30s, so in-flight orders finish.
  • Add build info for /actuator/info with the build-info goal of the plugin.