

Table of Contents
1. Overview
In this article, We will learn how to run a spring boot application using Maven or Gradle. Maven and Gradle are widely used build tools for dependency management, compiling and packaging the application. We can also run a spring boot application using those tools at the time of developing the application. For the maven command is mvn spring-boot:run
and for the Gradle command is gradle bootRun
but make for your Maven and Gradle is configured properly. Both the tools download dependency first (if not available in the local repo) and after that compile the application class and then run the application.
If you are new for spring and spring boot application development then there are so many articles related to spring boot which help you learn more about spring boot and it’s related modules: Spring boot tutorial.
2. Spring boot run using Maven & Gradle
2.1 Run application using Maven
Spring boot maven plugin has run goal using that we can compile and run spring boot application. for that
- Go to the root of the application where
pom.xml
is available - Run execute the below command
mvn spring-boot:run
Output:
[INFO] Scanning for projects... [INFO] [INFO] --------------< spring-boot-example:spring-boot-example >--------------- [INFO] Building spring-boot-example 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> spring-boot-maven-plugin:2.0.5.RELEASE:run (default-cli) > test-compile @ spring-boot-example >>> [INFO] [INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ spring-boot-example --- ... ... ... [INFO] [INFO] [INFO] --- spring-boot-maven-plugin:2.0.5.RELEASE:run (default-cli) @ spring-boot-example --- . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.5.RELEASE) 2019-06-30 09:46:15.501 INFO 5032 --- [ main] com.javadeveloperzone.SpringBootConfig : Starting SpringBootConfig on DESKTOP-6QDF17L with PID 5032 (F:\extrawork\slamba-git-repo\spring-examples\spring-boot-jackson-
2.2 Run application using Gradle
Spring boot Gradle contains task bootRun which help us to compile and run spring boot application:
- Go to the root of the application where
build.gradle
is available - Run execute the below command
gradle bootRun
Output:
Task :bootRun . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.9.RELEASE) 2019-06-30 09:57:38.494 INFO 11636 --- [ main] c.j.SpringBootApplication : Starting SpringBootApplication on DESKTOP-6QDF17L with
The term ‘gradle’ is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.If you are facing above error means that your Gradle is not properly configure, Here guide to install Gradle
2.3 Deploy Spring boot application
We can also run the application using our traditional way using java -jar
command but for that, we need to generate jar of out spring boot application, Let see those steps for Maven and Gradle:
1. Maven steps to build and run the application
mvn install
will generate the target directory in which two .jar files will be there. One .jar file with all the dependency and another ends with .ORIGINAL which contains only our class not the dependency classes. We can not use .ORIGINAL to run the application because it does not contain any dependency. Here are commands to build and run the spring boot application:
mvn install java -jar .\target\spring-boot-example-1.0-SNAPSHOT.jar
2. Gradle steps to build and run the application
Gradle also behaves the same like maven but it will generate jar inside the .\build\libs\
directory from there we can run the application.
> gradle build > java -jar .\build\libs\spring-boot-gradle-example-1.0.0.jar
3. Concussion
In this article, we learned about how to build and run a spring boot application using Maven and Gradle. We have also learned those commands using that we can archive our results.
4. References