DEV Community

Santhosh J
Santhosh J

Posted on

Apache Maven

Introduction

Maven in a build tool which is provided by Apache Software Foundation and is an open-source tool.

Why do we need Maven?

In a java project, we used to manually add the jar files to project's build path. This makes it difficult to manage the dependencies like upgrading them. We had to manually remove old jars, download new ones and add them to project's build path.
Maven makes this process easy. We just need to specify the dependencies in pom.xml file and maven takes care of downloading them and adding them to the project. It also provides a folder structure and we can add the necessary plugins as well.


Maven Project Structure

|-src
    |-main
        |-java
        |-resources
    |-test
        |-java
        |-resources
|-target
|-pom.xml
Enter fullscreen mode Exit fullscreen mode
  • src/main: Application code and dependent resource files written by developers.
  • src/test: Test code and dependent resource files written by developers (unit test cases) and SDET/QA (functional test cases)
  • target: Contains all the compiled classes, JAR files etc. When executing the mvn clean command, Maven would clean the target directory.
  • pom.xml: A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. The minimum requirement for a POM are the following:
    • project: root
    • modelVersion: should be set to 4.0.0
    • groupId: the id of the project's group.
    • artifactId: the id of the artifact (project)
    • version: the version of the artifact under the specified group
    • dependencies (optional): To add the dependencies. You can search and copy dependency from MVN Repository

L

Top comments (0)