In our last Selenium guide, we learned about a construction instrument named “Apache Ant”. We delved deeply into its usage and significance, along with its practical application.
In this Selenium Testing guide, we will delve into Maven – a construction automation instrument that is governed by the Apache Software Foundation. It is mainly employed for Java projects. It guarantees projects are consistently built.
Recommended IPTV Service Providers
- IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
- IPTVRESALE – Rating 5/5 ( 200+ Reviews )
- IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
- IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
- IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
- IPTVTOPS – Rating 5/5 ( 43 Reviews )
Maven is also used to manage dependencies. As an example, if you are using version 2.35 of Selenium and want to change to a different version later, this tool can handle it adeptly. We will talk more about this later in this tutorial. Maven works efficiently when dealing with numerous Jar files with diverse versions.
Primary Learning Points:
Understanding a build tool
A build tool is utilized to establish all the necessary prerequisites to run your Java code autonomously. It can be applied to your entire Java project. Activities such as generating source code, compiling the code, and packaging the code into a JAR file are carried out through it. Maven offers a common platform for these activities, making the coder’s life easier when handling large-scale projects.
Maven makes use of the pom.xml file, which is the heart of any project. It functions as the configuration file where all necessary information is stored. Various Integrated Development Environments (IDEs) like Eclipse, NetBeans, and IntelliJ are available to simplify its use.
Maven stores all project JAR files in a repository, which could be central, local, or remote. The needed dependency JARs are downloaded by Maven from a central repository. Most commonly used libraries are found at http://repo1.maven.org/maven2/.
Libraries that are downloaded are stored in the local repository, also known as the “m2” folder. Maven uses the libraries present in the “m2” folder. If any new dependency is added, Maven will download it from the central repository to the local one. If libraries are not available in the central repository, Maven searches for them in the remote repository. The user must configure the remote repository in the pom.xml file for downloads from it to occur.
Here’s an example of setting up a remote repository in the pom.xml file. Provide an ID and URL for the repository where the libraries are stored:
<repositories> <repository> <id>libraryId</id> <url>http://comanyrepositryId</url> </repository> </repositories>
Commonly used terms in Maven:
- groupId: Typically refers to a domain ID. It’s a best practice to use the company name as the groupId because it helps uniquely identify the project.
- artifactId: Essentially, it is the name of the JAR file sans the version.
- version: This tag is used to denote the project’s version.
- Local repository: Maven downloads all the necessary dependencies and stores them in the local repository known as “m2”. More details about this will be provided in the next topic.
Build Life Cycle
The foundational Maven phases are utilized as follows:
- clean: Erases all artifacts and targets created in the past.
- compile: Used to compile the project’s source code.
- test: Tests the compiled code. These tests don’t require packaging or deployment.
- package: Packages the project, transforming it into a JAR or WAR file, for instance.
- install: Installs the package into the local repository for other projects to use.
Maven Setup
Step 1: To set up Maven, download the latest Maven version from the Apache website that suits your system’s operating system.
Step 2: Extract the downloaded folder and save it on your local disk.
Step 3: Establish an environment variable for MAVEN_HOME. Follow these steps:
Go to System Properties -> Advanced System Settings -> Environment Variable -> System Variable -> New -> Add the Maven folder path.
Step 4: Modify the PATH variable and provide the path to the bin folder.
Step 5: Validate the Maven installation by using the command line and don’t miss out on setting up JAVA_HOME.
Use “mvn –version” to check the Maven version. The output should resemble the following:
Installation of Maven IDE in Eclipse
Maven offers IDE integration for Eclipse. Here, we will use Eclipse Juno for the demonstration.
Go to Help -> Eclipse Marketplace -> Search for “maven” -> Install “Maven Integration for Eclipse”
Once the installation is completed, restart Eclipse.
Subsequently, right-click on the pom.xml file and confirm that all the required options are accessible, as shown below.
Creating a Maven project:
Step 1: Navigate to File -> New -> Other -> Maven -> Maven Project -> Click Next
<a href=”https://iptvassist.com/wp-content/uploads/2021/12/Maven