SkillRary

Please login to post comment

Introduction to Maven

  • Amruta Bhaskar
  • Aug 28, 2020
  • 0 comment(s)
  • 2124 Views

Maven is a powerful project management tool that is based on POM (project object model). It is used for projects to build, dependency and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT.

In short terms we can tell maven is a tool that can be used for building and managing any Java-based project. maven make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.

 

What maven does?

Maven does a lot of helpful task like

  • We can easily build a project using maven.
  • We can add jars and other dependencies of the project easily using the help of maven.
  • Maven provides project information (log document, dependency list, unit test reports etc.)
  • Maven is very helpful for a project while updating a central repository of JARs and other dependencies.
  • With the help of Maven, we can build any number of projects into output types like the JAR, WAR etc without doing any scripting.

·        Using maven we can easily integrate our project with a source control system (such as Subversion or Git).

How does Maven work?

Core Concepts of Maven:

1.   POM Files: Project Object Model(POM) Files are XML file that contains information related to the project and configuration information such as dependencies, source directory, plugin, goals etc. used by Maven to build the project. When you should execute a maven command you give maven a POM file to execute the commands. Maven reads pom.xml file to accomplish its configuration and operations.

2.   Dependencies and Repositories: Dependencies are external Java libraries required for Project and repositories are directories of packaged JAR files. The local repository is just a directory on your machine hard drive. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository.

3.   Build Life Cycles, Phases and Goals: A build life cycle consists of a sequence of build phases, and each build phase consists of a sequence of goals. Maven command is the name of a build lifecycle, phase or goal. If a lifecycle is requested executed by giving maven command, all build phases in that life cycle are executed also. If a build phase is requested executed, all build phases before it in the defined sequence are executed too.

4.   Build Profiles: Build profiles a set of configuration values which allows you to build your project using different configurations. For example, you may need to build your project for your local computer, for development and test. To enable different builds you can add different build profiles to your POM files using its profiles elements and are triggered in the variety of ways.

5.   Build Plugins: Build plugins are used to perform a specific goal. you can add a plugin to the POM file. Maven has some standard plugins you can use, and you can also implement your own in Java.

Why Maven is Used?

As I said above it cuts down the tasks in the build process. To summarize, Maven simplifies and standardizes the project build process. It handles compilation, distribution, documentation, team collaboration and other tasks seamlessly. Maven increases reusability and takes care of most of the build-related tasks. It helps in bypassing my steps like adding jars to the project library, building reports, executing Junits test cases, creating Jar, War Ear files for the project deployment and many more. A very significant aspect of Maven is the use of repositories to manage jar files.

Few Glossaries around Maven

Maven Local Repository

This is the place where Maven stores all the project jars files or libraries or dependencies. By default the folder name is ‘.m2‘ and by default, the location in windows 7 is ‘Libraries\Documents\.m2‘.

Maven Central Repository

Maven central repository is the default location ‘http://mvnrepository.com/‘ for Maven to download all the project dependency libraries. For any library required in the project, Maven first looks into the .m2 folder of Local Repository, if it does not find the required library then it looks in Central Repository and downloads the library into the local repository.

Dependency Keyword

Dependencies are the libraries, which are required by the project. For example Log4j jars, Apache Poi jars, Selenium Jars, etc. Dependencies are mentioned in the Maven pom.xml like this:

   

         

                   org.seleniumhq.selenium

                   selenium-java

                   2.43.1

         

         

   org.seleniumhq.selenium

   selenium-java

   2.43.1

         

 

Surefire Plugin

The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in 2 different file formats like plain text file, XML files, and HTML files as well. Even if you are using TestNG or Junits framework for reporting, this plugin is a must to use, as it helps Maven to identify tests.

Maven POM

POM is a Project Object Model XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Some of the configurations that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on.

Please login to post comment

( 0 ) comment(s)