You can learn maven as a simple way . The maven it’s a tool by using simplifying the project building.
- Maven Provides Using developers way to following :
- Builds
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
- Mailing list
- Maven Project configure with .xml file pom.xml(POM-Project object model)
- Maven Environment Settings:
- Download maven repositories from “Maven 3.3 from http://maven.apache.org/download.cgi
- File name: apache-maven-3.3.3-bin.zip
- POM configuration:
- Project dependencies
- Plugins
- Goals
- Build profiles
- Project version
- Developers
- Mailing list
- Before creating The POM , we should first decide the project group(group Id) , Name(Artifact Id) and its Version .These Attributes are help in uniquely identifying the project repositories.
- Example program:
Pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
- The above code, Required Project element and three mandatory fields:groupId, artifactId and version.
- Projects notation in repository is groupId:artifactId:version.
- An easy way to look at the default configurations of the super POM is by running the following command: mvn help:effective-pom.
- Maven build life cycle is consists of following phases:
- Prepare-resource- resource copying can be customized in this phase.
- Compile- source code compile done in this phase
- Package- This phase create jar/war packages as mention in the xml file
- Install- This phase installs the package in local/remote maven repository.
- Maven has following three standard life cycle.
- Clean
- Default(or build)
- Site
[Note: mvn clean dependency:copy-dependencies package…command]
Clean Life cycle:
When we run mvn post-clean command, Maven invoke the life cycle phases.
- Pre-clean
- Clean
- Post-clean
Site Life cycle:
Maven Site plugin is generally used to create fresh documentation to create reports, deploy site etc.
Phases:
- Pre-site
- Site
- Post-site
- Site-deploy
Build profile:
A Build profile is a set of configuration values which can be used to set or override default values of maven build. Using a build profile, you can use customize build or different environments such as Production v/s deployment environments.
Profile are specified in pom.xml file using its active profiles /profile elements and are triggered in variety of ways. Profile modify the POM at build time, and are used to give parameters different target environment (for example: the path of the database servers in the deployment, testing and production).
Profile Activation project structure (Eclipse format):

Project Structure in eclipse
- Maven repositories are three types:
- Local
- Central
- Remote
- Maven plugins:
- Plugins are used for:
- Create jar
- Create war
- Compile code files
- Unit testing of code
- Create project document
- Create project report
- Plugins are used for:
- Maven plugin types:
-
Build plugin->they execute during the build and should be configured in the <build /> element in xml.
-
Reporting plugins->they execute the site generation and they should be configured in the <reporting /> element of the xml.
