Running Spring Boot with Maven: mvn spring-boot:run
Fast recall
Quick revision
Core answer
mvn spring-boot:run from the project root when the Spring Boot Maven plugin is configured. The goal compiles as needed and starts the application from the project classpath without first creating the packaged archive. A web application may start Tomcat, Jetty, Undertow, or a reactive server depending on its dependencies and configuration.Understanding of basic Spring Boot development workflow and familiarity with Maven plugin goals
Confusing development workflow (mvn spring-boot:run) with production deployment (java -jar) or not knowing that spring-boot:run doesn't create a JAR
Mention that spring-boot:run uses an exploded classpath which enables faster restarts with DevTools and allows running without the packaging overhead
Interview-ready guide
Interview answer
To run a Spring Boot app with Maven, you use the command mvn spring-boot:run from your project root.
This is the standard development workflow. The spring-boot-maven-plugin compiles your code, gathers all dependencies, and starts the Spring Boot application in one go. You don't get a JAR file with this approach — it runs directly from the compiled classes in your target directory.
It's like cooking and serving directly from the kitchen instead of packing everything into a takeout container first. This makes iteration really fast during development. You change your code, stop the app with Ctrl-C, run mvn spring-boot:run again, and you're back up.
One common mistake freshers make is running this command from the wrong directory. xml file is located, not inside src or target. Another pitfall is expecting this to create a JAR — it doesn't.
If you need a JAR for deployment, you'd use mvn package instead. The spring-boot:run goal is purely for development convenience. It's also worth knowing that this command works great with DevTools.
When you have DevTools as a dependency, you get automatic restarts when you recompile, which makes the development cycle even smoother. But again, this is a development-time tool. For production, you'd build a JAR and run it with java -jar.
Running Spring Boot with Maven: mvn spring-boot:run
Direct Answer
Run mvn spring-boot:run from the project root when the Spring Boot Maven plugin is configured. The goal compiles as needed and starts the application from the project classpath without first creating the packaged archive. A web application may start Tomcat, Jetty, Undertow, or a reactive server depending on its dependencies and configuration.
Code Example
// File: src/main/java/com/example/demo/DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello from mvn spring-boot:run!";
}
}
// Run from terminal: mvn spring-boot:run
// Access at: http://localhost:8080/hello
// Stop with: Ctrl+C
Common Mistakes & Pitfalls
- Running from wrong directory: Freshers often run mvn spring-boot:run from src/ or target/ instead of the project root where pom.xml lives, causing Maven to fail with "No plugin found" errors.
- Expecting a JAR to be created: Many assume this command creates a JAR in target/ like mvn package does — it doesn't, it runs directly from compiled classes.
- Not stopping cleanly: Using kill -9 instead of Ctrl+C can leave the port bound, causing "Port 8080 already in use" errors on the next run.
- Forgetting Maven installation: This command requires Maven to be installed and on PATH — it won't work if you only have the Maven wrapper (mvnw).
Check your understanding
Answer these without looking back at the article.
- What is spring-boot-devtools?
- What is the difference between mvn spring-boot:run and java -jar?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.