Forem

Hunor Vadasz-Perhat
Hunor Vadasz-Perhat

Posted on

spring-014: mvn spring-boot:run-lifecycle-phases

When you start your Spring Boot app using mvn spring-boot:run, Maven executes the necessary lifecycle phases in order. Hereโ€™s what happens at each phase:


1๏ธโƒฃ validate Phase

๐Ÿ”น What happens?

  • Maven checks the project structure and pom.xml configuration.
  • Ensures all required properties are defined.
  • Verifies that all dependencies are resolved (if any are missing, Maven will try to download them).

๐Ÿ”น Key tasks:

  • Ensures all necessary files exist (e.g., src/main/java, pom.xml).
  • Validates if groupId, artifactId, and version are correctly defined.

๐Ÿ“Œ If an issue is found (e.g., missing dependencies), Maven stops here with an error.


2๏ธโƒฃ compile Phase

๐Ÿ”น What happens?

  • Compiles Java source code (.java โ†’ .class files).
  • Stores compiled .class files inside target/classes/.

๐Ÿ”น Key tasks:

  • Uses the Maven Compiler Plugin to compile source files.
  • If annotation processing (e.g., Lombok) is enabled, it processes those annotations.

๐Ÿ“Œ If compilation fails due to syntax errors, Maven stops here.


3๏ธโƒฃ package Phase

๐Ÿ”น What happens?

  • Creates a JAR/WAR file containing the compiled classes and resources.
  • Moves the packaged file to target/your-app.jar (for Spring Boot, a fat JAR is created).

๐Ÿ”น Key tasks:

  • Runs spring-boot-maven-plugin (for Spring Boot apps) to package dependencies into the JAR.
  • Includes META-INF/MANIFEST.MF (defines the main class to run).
  • Copies src/main/resources/ files into the JAR.

๐Ÿ“Œ If packaging fails (e.g., missing files), Maven stops here.


4๏ธโƒฃ spring-boot:run (Runs the App)

  • JVM starts and loads Demo1Application.main().
  • Spring Boot initializes the app, loads dependencies, and starts an embedded web server (if applicable).
  • The app is now running and ready to serve requests.

๐Ÿ”„ Summary of Lifecycle Execution Before spring-boot:run

Phase Action Taken
validate Checks project structure, dependencies, and configuration.
compile Compiles .java files into .class files inside target/classes/.
package Bundles everything into a .jar/.war file in target/.
spring-boot:run Runs the packaged app using an embedded JVM.

๐Ÿ“Œ These phases ensure that when your app starts, everything is correctly compiled and packaged, preventing runtime errors. ๐Ÿš€

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post โ†’

Top comments (0)

Image of Docusign

๐Ÿ› ๏ธ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

๐Ÿ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay