Maven
Here , In this article you will see step by step setup of maven and why we need maven in our java project.
What is a maven ?
Apache Maven is the most used build management tool for java project. Its based on POM(Page Object Model).Without Maven , Everytime we have to include jars in our project but with maven we just need to add dependency in our pom.xml file present in our project
How to download Maven in Windows ?
This is pom.xml file present in our maven project.
<?xml version="1.0" encoding="UTF-8"?
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Maven_project2</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.31</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>>
What is a maven Repository?
A maven repository is a directory of packaged JAR file with pom.xml. There are three types of maven repositories:
Recommended by LinkedIn
How maven resolves dependencies ?
It scans all dependencies in pom.xml file. First searches in the local repository. If found, its quits. If in case he is not able to find then it scans in the central repository. If not found in central, it throws error.
Lifecycle of Maven
Lifecycle is the different stage of project Building .
5. Package(mvn package) - Downloads dependency from the central repository if not found in the local repository. Its adds the jar in the target folder but that jar is not present in the local.
6. Verify(mvn verify) - Its verifies whether the jar is present or not.
7. Install(mvn install) - It moves the jar and the pom that is present in the target folder to local repository that is .m2 so that we can add one project as a dependency and use it other project.
You can find the github link for this project below where maven has been used for more clarity
https://github.com/ash4491/DatabaseConnectivitywithMaven