Run Spring Boot Application using Command Line Tools

Apart from running a Spring Boot application on IDE, we can also run it as a standalone application using Command Line Tools.

Open the command line tool available on your application (like Windows Command Prompt, Unix Bash, etc.,) and execute the necessary commands to run the application as a standalone application.

NOTE: In order to run the application on a machine, it must contain JVM, which actually runs the application behind the scenes.

In this article, let's look at different ways.

Build the application

Before we run the application, we need to add the below Maven build plugin to pom.xml file and then build using any of the below commands, which generates the deployable artifact (JAR or WAR) file.

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

Any of the below commands generate a deployable JAR or WAR, which contains everything needed for the application to run as a standalone application, which can be deployed on any VMs or Container machines.

mvn clean install
mvn package

Run the application using Maven from Command Line Tools

Open the command line tool, go to the root of the application, and then execute the below command to run the application using Maven.

> mvn spring-boot:run

Run the application using Gradle from Command Line Tools

Open the command line tool, go to the root of the application, and then execute the below command to run the application using Gradle.

> gradle bootRun

Run the application using Java from Command Line Tools

Open the command line tool available on your application (like Windows Command Prompt, Unix Bash, etc.,) and execute the below command to run the application as a standalone application.

Where, artifact location is target/demo-0.0.1-SNAPSHOT.jar from the current path on the command prompt.

> java -jar target/demo-0.0.1-SNAPSHOT.jar
> java -jar target/demo-0.0.1-SNAPSHOT.war

Conclusion

Now, we know how to execute a Spring Boot application as a standalone application using command line tools.