Want to run a Spring Boot JAR from the command line without summoning a support ticket and without doing ritual sacrifices to the JVM gods? This short guide shows how to build obtain run and troubleshoot a runnable JAR with practical tips and a little attitude. You will learn how to produce the artifact start it with java -jar apply runtime flags run it in the background and make systemd behave like a grown up.
Produce a runnable Spring Boot artifact with your build tool of choice. Maven and Gradle both know the drill.
mvn package
# or for Gradle
./gradlew bootJar
Look for the output in target or build/libs and note the file name for the next step.
Use the standard Java launcher to start the app. No magic, just java.
java -jar myapp.jar
On Unix if your build produced an executable launch script style JAR you can make it runnable and start it directly.
chmod +x myapp.jar && ./myapp.jar
If that looks like a shortcut to chaos you can stick with java -jar and sleep better at night.
Control memory, profile, port and logging with JVM and Spring Boot arguments. Example:
java -Xmx512m -jar myapp.jar --server.port=8081 --spring.profiles.active=dev
Need the app to survive when you log out Use a process manager rather than a terminal trick. If you are lazy use nohup or run with ampersand and disown while you plan a proper fix.
nohup java -Xmx512m -jar myapp.jar --server.port=8081 > myapp.log 2>&1 &
Most startup problems are the kind you do not want to reintroduce. Check these first.
If you see class not found or bootstrap errors check the build logs and ensure dependencies were packaged correctly by your build tool.
For reliable service style management use a systemd unit to start stop and restart your app. This keeps logs accessible and lets the system restart on failure without your intervention.
[Unit]
Description=My Spring Boot app
After=network.target
[Service]
User=spring
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/java -Xms256m -Xmx512m -jar /opt/myapp/myapp.jar --spring.profiles.active=prod
SuccessExitStatus=143
Restart=on-failure
[Install]
WantedBy=multi-user.target
Enable the unit and use journalctl to inspect logs or configure an external log aggregator if you enjoy long term happiness.
Summary Run locally with java -jar for debugging. Use JVM flags and Spring Boot properties to tune behavior. For production use systemd or a container manager and capture logs separately. Check the logs and the JVM version before you panic and lose hair over a port conflict.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.