Sitemap
D-Adda

D-Adda

DevOps Engineer

Maven

3 min readDec 7, 2024

--

  • Maven is an open source automation and project management tool developed by Apache.
  • It simplifies the build process, dependency management, and project configuration by using a declarative model.
  • Mostly used for java based projects.
  • Maven is written in java.
  • It is used to build artifacts.
  • POM.xml (Project Object Model) main configuration file in maven.
  • Pom.xml files created in the project’s home directory’s workspace.
  • POM.xml file has all the information regarding project and configuration details.
  • Every single project has their own pom.xml file.
  • Its core feature is dependency management, which helps manage external libraries and simplifies the process of including them in our project. However, Maven offers more than just dependency management; it also provides a framework for defining project structures, executing build tasks, running tests and creating project documentation.

What is artifact in Maven?

An artifact refers to a file or collection of files that is produced as a result of the build process and can be used or distributed further. Artifacts are typically output files like JARs, WARs, EARs, or ZIPs.

Get D-Adda’s stories in your inbox

Join Medium for free to get updates from this writer.

In Maven, an artifact is the final product of the project after it has been built and packaged. It is often a library or application that is ready to be used or deployed.

Key Features of Apache Maven:

1.Project Object Model (POM):

  • The core of Maven is the POM file (pom.xml), which contains information about the project, such as its dependencies, plugins, goals and build profiles. It defines the configuration and setup of the project.

2. Dependency Management:

  • Maven allows projects to automatically download and manage dependencies (external libraries or JAR files) from a central repository. It uses transitive dependency resolution, meaning it will also download dependencies of our dependencies.

3. Standardized Build Lifecycle:

  • Maven follows a standardized build lifecycle with phases such as clean, compile, test, package, install and deploy. Each phase performs a specific task in the build process, ensuring consistency across different projects.

4. Repositories:

  • Maven uses central repositories to fetch dependencies. We can also configure it to use other remote or local repositories.

5. Plugins:

  • Maven supports numerous plugins that can extend its functionality, such as compiling code, running tests, generating reports and packaging the application.

6. Multi-Module Projects:

  • Maven supports multi-module projects, where a parent POM can manage several sub-modules, allowing a streamlined build process for complex systems.

7. Integration with IDEs:

  • Maven can integrate with popular IDEs such as IntelliJ IDEA, Eclipse, and NetBeans, making it easy to manage dependencies, build and run projects directly within the IDE.

8. Cross-Platform:

  • As a Java-based tool, Maven works on all platforms that support Java (Windows, Linux, macOS).

Maven Installation:

Maven Installation on amazon linux 2
====================================

Step-1 (Install java)
sudo yum update -y
sudo yum install java-1.8.0-openjdk-devel -y # download any version 8 or 11
java -version # verify java version

Step-2 (Install Maven)
wget https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz
tar xzvf apache-maven-3.9.0-bin.tar.gz #Extract the downloaded archive
sudo mv apache-maven-3.9.0 /opt/maven # Move Maven to the appropriate directory
mvn -version # Verify the Maven Installation

How Maven Works:

  1. Build Process: When we run a Maven build, it reads the pom.xml, downloads dependencies and performs tasks defined by the build lifecycle. Maven then executes these tasks step by step (e.g., compiling code, running tests, packaging).
  2. Dependency Management: Dependencies are specified in the pom.xml, and Maven downloads them from central or custom repositories. The dependencies' versions are automatically resolved.
  3. Standard Directory Structure: Maven projects follow a standard directory layout, for example:
  • src/main/java: Main source code
  • src/test/java: Unit test code
  • target: Output of the build process (compiled code, JAR/WAR files)

When to Use Maven:

  • When we are working with Java-based projects and need to automate the build process.
  • When managing complex projects with multiple dependencies.
  • When we need a standardized way of building, packaging and deploying projects.

--

--