SoFunction
Updated on 2025-04-13

JAVA SpringBoot jar program Systemctl production environment deployment solution

JAVA SpringBoot jar program Systemctl production environment deployment

Using systemctl in Linux systems to manage and automatically start a Spring Boot application, you need to package the Spring Boot application into an executable JAR file and create a systemd service unit file.

A simple step guide and sample service file

  • Make sure that the Spring Boot application has been packaged into an executable JAR file.
  • Create a new service unit file /etc/systemd/system/

The content is as follows:

[Unit]
Description=Your Spring Boot Application
After=
 
[Service]
User=ubuntu
ExecStart=/usr/bin/java -jar /path/to/
SuccessExitStatus=143
 
[Install]
WantedBy=

Make sure to modify User as the user running the application and ExecStart as the full path to the JAR file.

  • Reload the systemd manager configuration to make the new service unit take effect:
sudo systemctl daemon-reload
  • Start the application service:
sudo systemctl start 
  • Set the application service to start automatically:
sudo systemctl enable 

Make sure that the Spring Boot application has the appropriate log configuration so that systemd can correctly log output and error messages.

If the application requires additional configuration, it can be passed through environment variables or command line parameters.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.