Run Spring Boot App from a Command Line

With this blog post, I am going to share with you how to run a Spring Boot app from a command line in a Terminal window. There are a couple of ways and both assume that you have already created your Spring Boot app. To learn how to create a new Spring Boot app please check the below blog post of mine.

Create a Simple Web Service Project with Spring Boot

Add Maven Plugin to POM.XML

For us to be able to run Spring Boot application as a single executable Java jar file we first need to update the pom.xml file of our project and add to it a maven plugin.

Open the pom.xml file and add the following XML snippet below the list of project dependencies.


Build Spring Boot Project with Maven

To be able to run your Spring Boot app you will need to first build it. To build and package a Spring Boot app into a single executable Jar file with a Maven, use the below command. You will need to run it from the project folder which contains the pom.xml file.

maven package

or you can also use

mvn install

Run Spring Boot app with java -jar command

To run your Spring Boot app from a command line in a Terminal window you can you the java -jar command. This is provided your Spring Boot app was packaged as an executable jar file.

java -jar target/mywebserviceapp-0.0.1-SNAPSHOT.jar

Run Spring Boot app using Maven

You can also use Maven plugin to run your Spring Boot app. Use the below example to run your Spring Boot app with Maven plugin:

mvn spring-boot:run

Run Spring Boot App with Gradle

And if you use Gradle you can run the Spring Boot app with the following command:

gradle bootRun

Automatic Restart and Hot Swapping

Applications that use spring-boot-devtools dependency automatically restart whenever files on the classpath change. Although for this to work you will need to run your Spring Boot App using IDE.


Run Spring Boot Web Service as a Standalone App. Video Tutorial.

2 Comments on "Run Spring Boot App from a Command Line"

  1. Very usefull, direct and clear tip you go to the point. Many thanks.

    To Goutham: yes, to address that aproach will be better to debug directly on the IDE of your preference, simply run the Spring boot application under “debug mode” clicking in the class that holds the “main” method, then you will see in you IDE’s console the Spring Boot is running and “lifting the aeroplane” once the application is up you need to send a request by POSTMAN/SOAP UI/Web Browser and that’s all… remember to put a break point inside of your code if this not happen the debug mode will be same as run.


Leave a Reply

Your email address will not be published. Required fields are marked *