Quickly run a Spring Boot JAR file at the Command Line |Video upload date:  · Duration: PT1M0S  · Language: EN

Run a Spring Boot JAR from the command line fast with clear steps common flags and quick troubleshooting tips

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.

Build or get the JAR

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.

Run the JAR on the command line

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.

Pass JVM and Spring Boot flags and run in background

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.

  • Quick and dirty background run with nohup and a log file
    nohup java -Xmx512m -jar myapp.jar --server.port=8081 > myapp.log 2>&1 &
  • Use a real process manager for production like systemd or a container orchestrator

Troubleshooting startup issues

Most startup problems are the kind you do not want to reintroduce. Check these first.

  • Missing JDK on the host Verify java -version shows a compatible runtime
  • Wrong artifact Confirm the file is an executable Spring Boot JAR and not a library jar
  • Port conflict If the port is in use change it with --server.port or stop the other service
  • Low visibility Increase logging with --logging.level.root=DEBUG and inspect stdout or the log file for stack traces

If you see class not found or bootstrap errors check the build logs and ensure dependencies were packaged correctly by your build tool.

Use systemd for reliable production starts

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.