What is Maven in Spring Boot?
Maven is a build automation and project management tool used in Java projects. In Spring Boot, Maven handles:
Downloading dependencies (libraries/jars) automatically
Compiling your Java code
Running tests
Packaging your app into a .jar or .war file
Deploying your application
What Maven Actually Does
Maven mainly handles 3 things:
Dependency Management
It downloads required libraries automatically.
Example:
You want to use MySQL in Spring Boot.
Without Maven:
search MySQL connector online
download jar
add to project manually
With Maven:
just add this in pom.xml
<dependency> <groupId> mysql </groupId> <artifactId> mysql-connector-j </artifactId> <version> 8.3.0 </version> </dependency>
Enter fullscreen mode
Exit fullscreen mode
Maven downloads it automatically from the Maven repository.
Build Automation
Maven can:
compile code
run tests
package project
create .jar or .war
Instead of: javac Main.java
You simply run: mvn compile
To create a JAR: mvnβ¦