This tutorial will teach you how to run a Spring Boot application from the Command Line using different options.
In order to run a Spring Boot application, first of all, make sure you have included the Maven plugin in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Next, make sure you build your application with:
mvn install
Now you are ready to run your Spring Boot application!
Run the Spring Boot application using java -jar
You can still rely on the java -jar option to run the SpringBoot Uber Jar file:
java -jar target/app-0.0.1-SNAPSHOT.jar
Running Spring Boot with Maven plugin
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
What if your application includes more than one Application Class ? then you have to specify which one is the entry point:
<?xml version="1.0" encoding="UTF-8"?><plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<mainClass>com.example.MyApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Running Spring Boot with Gradle
Using Gradle to build your Spring Boot application? then you can simply run it with:
gradle bootRunFound the article helpful? if so please follow us on Socials