Running Spring-boot from the command line

Manish Kumar
2 min readApr 4, 2021

During our development, we spend most of the time in IDE. However, we may encounter a situation where we want to run our spring boot app from outside of the IDE.

How to run from the command line?

Since we are using spring boot, the server is embedded in the JAR file itself. We no need to have any server process running.

Spring boot apps are self-contained. The jar itself will become the process and the server will become a part of it.

We have two way for running the app from the command line:

  1. java -jar app.jar
  2. mvn spring-boot:run

Option 1)

java -jar app.jar

Here we can just pass the generated executable application jar, and it will start the embedded server and run our app.

Option 2)

we can use spring-boot maven plugin. If you are using maven then write below in the pom.xml file.

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Once you added the above configuration in the pom.xml file now we can use the below command to run the spring boot app.

mvn clean package // this will package the application. Its must to        run very first time.
mvn spring-boot:run // This will run the app

That's it!!!

Happy Learning.

--

--