Spring Boot packages your application and an embedded web server (Tomcat by default) into one executable JAR, so deployment is mostly about running Java reliably: the right runtime version, a heap that fits the server, a supervisor that restarts the process, and a reverse proxy for TLS. This guide covers each step on Ubuntu 24.04 or Debian 12.
Step 1: Install the Java Runtime
Use the same major Java version your project is compiled for (check java.version in pom.xml or the toolchain in build.gradle). Spring Boot 3.x requires Java 17 or later. On Ubuntu 24.04:
sudo apt update
sudo apt install -y openjdk-21-jre-headless
java -version
The -headless package omits desktop libraries you do not need on a server. Eclipse Temurin builds from Adoptium are a common alternative if you need a specific vendor or update cadence.
Step 2: Build the Executable JAR
Build in CI or on your workstation:
# Maven
./mvnw -DskipTests package
# Gradle
./gradlew bootJar
The result is in target/ or build/libs/. Use the file without the -plain suffix: that one is the fat JAR containing all dependencies.
Step 3: Production Configuration
Keep environment-specific settings out of the JAR. Spring Boot reads environment variables automatically, mapping SPRING_DATASOURCE_URL to spring.datasource.url, and also reads an external application.properties placed next to the JAR or in a config/ subdirectory. A production profile might set:
# /opt/app/config/application-prod.properties
server.address=127.0.0.1
server.port=8080
server.forward-headers-strategy=framework
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s
management.endpoints.web.exposure.include=health,info
management.endpoint.health.probes.enabled=true
server.address=127.0.0.1keeps the embedded server private; only Nginx reaches it.server.forward-headers-strategy=frameworkmakes Spring honourX-Forwarded-*headers, so redirects usehttpsand logs show the real client IP. Only enable it when a trusted proxy always sets those headers.server.shutdown=gracefullets in-flight requests finish when the service stops.- Expose only the Actuator endpoints you need.
/actuator/healthis safe;env,heapdumpand similar must never be public.
Secrets such as database passwords go in an environment file read by systemd:
sudo adduser --system --group --home /opt/app app
sudo tee /opt/app/.env >/dev/null <<'EOF'
SPRING_PROFILES_ACTIVE=prod
SPRING_DATASOURCE_URL=jdbc:postgresql://127.0.0.1:5432/app
SPRING_DATASOURCE_USERNAME=app
SPRING_DATASOURCE_PASSWORD=use-a-long-random-password
EOF
sudo chown app:app /opt/app/.env && sudo chmod 600 /opt/app/.env
Step 4: Size the JVM Memory
The JVM uses more than the heap: metaspace for classes, a stack for every thread, code cache, direct buffers and garbage-collector overhead. A rough budget for a typical web service is heap + 300–500 MB. Set the heap explicitly so the JVM never grows into memory the database needs:
| Server RAM | Also running | Suggested -Xmx |
|---|---|---|
| 8 GB | PostgreSQL + OS | 2–3 GB |
| 16 GB | PostgreSQL + Redis | 4–6 GB |
| 32 GB | Several services | Per service, sum well below RAM |
Alternatively, use -XX:MaxRAMPercentage=50 to size the heap as a share of available memory. Check real usage with ps -o rss,cmd -C java after the application has warmed up, and add a small swap file as a safety net (see our swap guide).
Step 5: Run It with systemd
sudo install -o app -g app -m 0644 -D app.jar /opt/app/app.jar
sudo tee /etc/systemd/system/app.service >/dev/null <<'EOF'
[Unit]
Description=Spring Boot application
After=network-online.target postgresql.service
Wants=network-online.target
[Service]
User=app
Group=app
WorkingDirectory=/opt/app
EnvironmentFile=/opt/app/.env
ExecStart=/usr/bin/java -Xms512m -Xmx2g -XX:+ExitOnOutOfMemoryError -jar /opt/app/app.jar
SuccessExitStatus=143
Restart=on-failure
RestartSec=5
TimeoutStopSec=40
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now app
journalctl -u app -f
SuccessExitStatus=143treats the JVM's normal response to SIGTERM (exit code 143) as a clean stop, so systemd does not log a failure on every restart.-XX:+ExitOnOutOfMemoryErrormakes the JVM exit on an out-of-memory error so systemd restarts it, instead of leaving a half-working process.TimeoutStopSecshould exceed the graceful shutdown timeout.
Spring Boot starts slower than Go or Node.js; allow 10–60 seconds depending on the application before health checks fail it.
Step 6: Nginx and HTTPS
server {
listen 80;
server_name app.example.com;
client_max_body_size 20m;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
location /actuator/ {
allow 127.0.0.1;
deny all;
proxy_pass http://127.0.0.1:8080;
}
}
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d app.example.com
The second location blocks public access to Actuator; your monitoring can query it from the server itself. Our Let's Encrypt guide covers certificates in detail.
Step 7: Deploying New Versions
scp target/app-1.5.0.jar deploy@server:/tmp/
ssh deploy@server 'sudo install -D -o app -g app -m 0644 /tmp/app-1.5.0.jar /opt/app/releases/app-1.5.0.jar \
&& sudo ln -sfn /opt/app/releases/app-1.5.0.jar /opt/app/app.jar \
&& sudo systemctl restart app'
curl -fsS http://127.0.0.1:8080/actuator/health
Keep previous JARs in releases/ so rolling back is a symlink change and a restart. Database migrations (Flyway or Liquibase) run on startup; write them to be backward compatible so a rollback does not break on a newer schema.
Alternative: Container Image
Spring Boot can build an OCI image directly with ./mvnw spring-boot:build-image or ./gradlew bootBuildImage. If you deploy with Docker, publish the port only on 127.0.0.1 and keep Nginx in front; see our Docker deployment guide.
SkyRainCloud Plans for This Workload
Java services need more memory than most stacks: the JVM heap, metaspace and thread stacks all add up. A single Spring Boot service with PostgreSQL is comfortable on 8 GB; several services or large heaps call for the 16 GB and 32 GB tiers.
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check stock |
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
UnsupportedClassVersionError | The runtime is older than the Java version used to compile; install the matching JRE |
Process killed, OOM in dmesg | Heap plus non-heap exceeds RAM; lower -Xmx or move to a larger plan |
Redirects go to http:// | Set server.forward-headers-strategy=framework and pass X-Forwarded-Proto |
| 502 right after restart | The app is still starting; check journalctl -u app and wait for "Started ... in N seconds" |
| Port 8080 already in use | Another instance or service is running: sudo ss -tlnp | grep 8080 |
Frequently Asked Questions
Which Java version do I need for Spring Boot?
Should I run the JAR directly or use Tomcat separately?
How much RAM does a Spring Boot app need?
How do I set the JVM heap size?
-Xms and -Xmx in the systemd ExecStart line, or use -XX:MaxRAMPercentage to size it relative to available memory.Why does systemd report my Spring Boot service as failed when I stop it?
SuccessExitStatus=143 to the unit so systemd treats it as a normal stop.How do I make Spring Boot work behind Nginx with HTTPS?
X-Forwarded-Proto and related headers, and set server.forward-headers-strategy=framework.Is it safe to expose Spring Boot Actuator?
health and info, and restrict the /actuator/ path to localhost or an internal network. Endpoints like env and heapdump can leak secrets.How do I deploy a new version without long downtime?
Where are Spring Boot logs on the server?
journalctl -u app. Configure file logging with rotation only if you need log files.