Introduction to Apache Maven
What is Maven?
Apache Maven is a build automation tool used primarily for Java projects. It describes how software is built,
and it can manage dependencies, documentation, and other project-related tasks from a central piece of
configuration called a POM file.
Key Features of Maven
- Simplifies project builds with a standard directory layout
- Automatically downloads project dependencies
- Provides lifecycle management (compile, test, package, install, deploy)
- Supports plugin-based architecture
- Generates useful project reports and documentation
Maven Terminology
- POM (Project Object Model): XML file (pom.xml) containing project configuration
- GroupId: Uniquely identifies your project across all projects
- ArtifactId: The name of the jar without version
- Version: Version of the artifact
- Dependencies: External libraries required by the project
Installing Maven
1. Download Maven from the official website.
2. Extract and configure the `MAVEN_HOME` and add `bin` to the system PATH.
3. Verify installation with `mvn -v`.
Creating a Maven Project
Use the following command:
mvn archetype:generate -DgroupId=com.example -DartifactId=my-app
Introduction to Apache Maven
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Maven Lifecycle Phases
- validate: Validates the project is correct
- compile: Compiles source code
- test: Runs unit tests
- package: Packages the compiled code
- install: Installs the package to local repository
- deploy: Copies package to remote repository
Conclusion
Maven is a powerful tool that simplifies Java project management. Understanding its basics like the POM file,
dependencies, plugins, and lifecycle phases can significantly improve productivity and project consistency.