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.

原文链接:spring-014: mvn spring-boot:run-lifecycle-phases

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
Everyone has its disadvantage just like the god bites the apple. the bigger disadvantage you have, the more the god appreciate it.
每个人都会有缺陷,就像被上帝咬过的苹果,有的人缺陷比较大,正是因为上帝特别喜欢他的芬芳
评论 抢沙发

请登录后发表评论

    暂无评论内容