In this article we learn the what is maven, how to install maven in eclipse, how to create maven project in eclipse, what is pom.xml, maven repository and types of maven repository.
What is Maven?
MAVEN helps us in creating the project structure, managing, and downloading the dependencies. We need to define the required dependencies in pom.xml. We will look more in detail. (By default, maven adds few dependencies specific to project structures and that will be based on the archetype that we choose).
Maven is a build / project management tool, based on the concept of a project object model (POM) contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
How To Install Maven in Eclipse?
1. Google Search -> Download Maven -> Click on link (https://maven.apache.org)
2. Open Maven Website -> Scroll Down->Files->Binary zip archive->Click On ‘apache-maven-3.8.4-bin.zip’ -> Downloading Start.
3. After Completion of downloading, Move that Zip file to the respective location.
4. Extract that downloaded file.
5. Set Path for Maven
6. We need to set up is the PATH variable, the reason we do this is that we can trigger maven executable command from anywhere in your command prompt and it will point to the MAVEN executable which is in the BIN folder.
7. Open My Computer-> Right click on the black space->Properties->Advance System Setting >Environment Variable-> Check only System variables->Click On New ->Variable Name – “MAVEN HOME”, Variable Value -Paste the path upto bin folder of Apache maven. ->click Ok.
8. In System Variable, click on “Path”-> Edit->Add-> Paste the path upto bin folder of Apache maven -> Click Ok.
9. Click on Window Search Button-> Search “Command Prompt” or “CMD”
Type “java -version” -> Enter -for checking Java Version.
Type “mvn -version” -> Enter -for checking Maven Version.
How To Create a Maven project In Eclipse?
Step 1: Navigate to File Menu -> New, and check if Maven Project is displaying if yes, click on Maven Project. If NOT, please click on other.
Step 2: After Clicking on Other, it will display ‘select a wizard’ screen, please type as Maven in the text box to filter and find aven. After that Select Maven and Click on next button.
In the next screen, it will ask us to select project name and location. By default, ‘Use default workspace location’ will be selected. Just click on next button to proceed without making any changes.
Step 3: In the next screen, It will ask us to select an [ Archetype maven- archetype-quickstart version-1.4]. Depending on the type of project that we are working, we need to choose the archetype.
Step 4: It will ask us to ‘Enter a group id for the artifact.’ Version number will be by default 0.0.1-SNAPSHOT
Step 5: Click on Finish. Now Creating a maven project is Done.
After that, it has downloaded Maven Dependencies. We can see by expanding the Maven Dependencies. And also, it has created pom.xml file.
Dependency for WebdriverManager in POM.XML File:
1. WebDriverManager in Selenium, is a class that allows us to download and set the browser driver binaries without us, as developers, having to put them in automation scripts manually.
2. Automates the management of WebDriver binaries.
3. Downloads the appropriate driver binaries, if not already present, into the local cache.
4. Downloads the latest version of the browser binary, unless otherwise specified.
5. Eliminates the need to store driver binaries locally. We also need not maintain various versions of the binary driver files for different browsers.
In Maven project, we need to add the following dependency in Pom.XML
1. Google search->” WedriverManager Maven Dependency”-Enter
2. Go to on Website- “https://mvnrepository.com “ -> Click On updated Version of WebDriver Manger-> Copy Webdriver Manger Dependency as below and paste in Pom.XML file.
What is pom.xml?
POM is an acronym for Project Object Model. It contains information about project and configuration of the project such as dependencies, build directory, source directory, test source directory, plugins, goal, etc. Maven reads pom.xml and then executes goal.
Why should we use Maven?
1) We need maven to get all our dependencies automatically, which also allows users to reuse same jars across multiple projects.
2) Each and every engineers in a project use the same jar dependencies due to the centralized POM.
3) It provides the complete structure with naming conventions which is easy to locate and execute tests.
4) We can automate the complete build procedure etc.
Maven repository is a directory where all the dependencies such as jars, library files, plugins, or other artifacts that will be required by the projects are stored.
These repositories help us to store and maintain useful resources so that they can be used in our maven projects while building and deploying the artifacts.
All the layout and structure of the underlying repositories of maven of any type are completely hidden for maven users.
Type of Repositories
1) Local Maven Repository
2) Remote Maven Repository
3) Central Maven Repository
1) Local Maven Repository: –
Local repositories are the folders or directory on our machine where maven is used i.e., a local machine that contains the cached jars and dependencies required by your project and other artifacts that are built by us on our machine but not released yet.
The operations that the maven user can perform is to clean the local repository if any memory or space-related issue is there on their local repository or completely erase the data on this repository that will further lead to re-downloading of the dependencies required by our project.
2) Remote Maven Repository
The remote repositories are the resources that are located remotely and contain directory having jars, library files, and plugins, and other artifacts that might be useful and are accessed by using the protocols such as https:// of file://protocol.
These remote repositories are further segregated into the repositories that are kept at a remote place and shared between multiple individuals and developers for the private use of a company or the third party to maintain and share artifacts.
We can mention our remote repositories inside the settings.xml file in the repositories tag and can add multiple repository tags for multiple remote repositories.
3) Central Maven Repository
The second remote repository in the maven is the central repository that is available for downloading the dependencies in our maven project and also to release the artifacts that we want to on the central repository.
The link for the central maven repository is https://repo.maven.apache.org/maven2 while the site that is available for searching the maven dependencies available in the central repository of maven is – https://search.maven.org/.
This type of remote repository is also called and referred to as the central repository and is available to all and is open source.
This repository is provided by the maven community. There is no need for any configurations in settings.xml file for a central repository.