EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Boot Run Command
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Boot Run Command

Spring Boot Run Command

Definition of Spring Boot Run Command

Spring boot run command is defined as a methodology to run spring boot applications through the use of a command-line interface. Generally, during the development of the spring boot application, we try to run the application using the integrated development environment or in other words IDE, but as we try to launch the spring boot application in the production environment, it becomes inevitable to use the command-line interface to run the spring boot application as the production environment might not always support an IDE. Spring boot as an application development tool does accelerate the development process by providing a lot of starter packs and initializers. Bundling up the different elements and running them in the environment is what we will talk about in detail in this article.

Syntax of Spring Boot Run Command

The spring boot run command, as mentioned, is a methodology for running spring boot applications in mainly production environments. There are many ways in which this capability can be achieved but adhering to the length of the article we will talk about the most frequent ways in the professional world.

Generate a Maven artifact from a Spring Boot application:

mvnclean install

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,697 ratings)

This method needs to run the FAT JAR which gets build post the run of the install command.

Running of jar file created (Read this as FAT JAR):

java -jar <jar file name>

Running the Spring Boot without building the FAT JAR using Maven installed:

mvnspring-boot:run

Run maven if when maven is not installed in the system:

mvnw install

mvnw and mvnw.cmd are the 2 wrappers which we get when we download our Spring Boot project from Spring Initializer i.e. https://spring.io. This method needs to run the FAT JAR which gets build post the run of the install command.

Running the Spring boot application from the source directory without building FAT JAR:

mvnwspring-boot:run

Make sure that the spring-boot plugin is a part of the pom.xml while making list of dependencies in the pom.xml. Here there is no build of FAT JAR and hence no requirement of running java -jar command and even without that the spring boot application would launch.

How does Run Command Work in Spring Boot?

  • In this article we will focus our efforts on understanding 2 aspects, one of them is to run the Spring Boot application while we have maven installed in our system, and the other by using a workaround of running the Spring Boot application without maven installed in our system. In addition, there are 2 different varieties that are present in each of the cases mentioned above while running the Spring Boot application. In one we can build a FAT JAR and then run the FAT JAR while the other is to bypass the build of FAT JAR and run the Spring Boot application without it.
  • Let us first start with the concept of running the spring boot run command with the maven installed in the system. For that first, we will have to install Apache Maven in the system. One can download the zip file of the apache maven, extract that zip and add the bin folder with the mvn command to the PATH in the environment variables. Once maven is in place, if the developer runs mvn install, the Spring Boot project is compiled, tested, and then packaged, and finally build the .jar file into the local maven repository. While building the jar file it takes care of the dependency management where 3rd party dependencies are included in the project. The JAR file is built with convention as maven expects a certain directory structure for it to be compiled and an mvn clean install does the job of compilation and packaging work. It also runs some code quality checks along with the execution of test cases. Not only that but the application can also be deployed to remote servers through plugins. Once that JAR file is built, we can run the java -jar command to run the application in the environment where the application will be deployed.
  • The alternate to run the spring boot without building the JAR file is to run the command mvnspring-boot:run. This command makes sure that the POM.xml has the plugin which signifies that we want to use Tomcat to run our code. When the code is run in the project root folder the plugin reads the POM.xml and understands that a web application container is needed and thus triggers the download of Apache tomcat. Once all things are downloaded, the spring boot server runs automatically and launches the application as a spring boot application.
  • The ./mvnw command is no different from maven clean install and just allows the developer to not have a dependency of maven installed into the system. This wrapper file is obtained while we download the spring boot project from the spring initializer. This works very similar to fully installed maven except for the fact that maven is not actually installed. Apart from that the other commands like a clean install, and spring-boot: run works the same way as it does for cases of mvn.

Examples of Spring Boot Run Command

For the examples, we will use the same spring boot codes and demonstrate both cases!

Pom.xml: (Make sure below dependency is present):

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
startWeb.java
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class startWeb {
@RequestMapping("/")
public String home() {
return "Hello Readers";
}
}
RuncommanddemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RuncommanddemoApplication {
public static void main(String[] args) {
SpringApplication.run(RuncommanddemoApplication.class, args);
}
}

Example #1

Running with mvn and FAT JAR:

Syntax:

mvn clean install
cd target
java -jar <jar file name>

Output:

Spring Boot Run Command-1.1

Spring Boot Run Command-1.2

Spring Boot Run Command-1.3

Spring Boot Run Command-1.4

Example #2

Running with mvnwspring-boot:run:

Syntax:

mvnwspring-boot:run

Output:

Spring Boot Run Command-1.5

Conclusion

In conclusion, in this article we have learned about the working of spring boot run command along with the flexibility spring boot provides to the developers with various alternatives to choose from and act as per convenience. The rest 2 cases of “mvn and spring-boot: run” and “mvnw and FAT JAR” are left to the readers for hands-on experience!

Recommended Articles

This is a guide to Spring Boot Run Command. Here we also discuss the introduction and how does run command work in spring boot? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Spring Boot DevTools
  2. Spring Boot Starter Web
  3. Spring Boot Annotations
  4. Spring Boot Versions
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more